How to use edge rails? - ruby-on-rails

The title says it all. There are really old questions that ask the same thing, but I think rails has moved on since then.
In my Gemfile, I've tried:
gem 'rails', github: 'rails/rails'
But that gives me 6.1.0.rc1 be11d1b once I run bundle install. Current version of rails as of this writing is 6.1.3. Also tried bundle update rails after using the above line in the Gemfile. So it seems that a version older than current is being used when I try to pull from GitHub...?

Here's what I wound up doing:
gem 'rails', github: 'rails/rails', branch: 'main'
The branch part has to be there to make it do what I wanted. I tracked it down with
rails new --help, which led me to the --edge and --master options. Starting a new app with rails new app_name --master actually got me where I wanted to go.

Related

I'm developing a Ruby gem, how can I try it out locally with my Rails app?

I am developing a gem meant to be used with Rails projects and want to try it out locally with another Rails app of mine.
I built the gem with bundle exec rake release which put a .gem file in the /pkg directory.
Then, in my Rails app, I added the following to my gemfile
gem 'mygem', '0.1.1', path: '/Users/me/projects/mygem/ruby/pkg'
I then ran bundle install which said it installed the gem. When I do this, it removes the gem from the path. IDK where it went.
When I start the Rails app, it's like the gem isn't included at all.
Interestingly, if I add a version that doesn't even exist, it still says bundle install works fine. (Example: gem 'mygem', '0.1.2345', path: '/Users/me/projects/mygem/ruby/pkg')
What am I supposed to do to try out my Gem locally with a Rails app?
This question is different from How can I specify a local gem in my Gemfile? because I explicitly tell bundle in my Gemfile to use the local gem, with the path given, and it still doesn't work. When I run bundle install, it says
Using mygem 0.1.1 from source at /Users/me/projects/mygem/pkg
So you'd think it works right, but it still doesn't.
Interestly, if I try it with a version number that doesn't exist, like mygem 1.2.3, it still runs bundle install successfully, which is really weird and seems like a bug:
Using mygem 1.2.3 (was 0.1.1) from source at /Users/me/projects/mygem/pkg
I prefer to use the following when working on a local gem side-by-side with a Rails project:
gem 'foo',
:git => '/path/to/local/git/repo',
:branch => 'my-fancy-feature-branch'

Ruby On Rails, Where Do Bundler install gems that are fetched with :git=>'/your_name/project_name.git'?

This is my first question on StackOverflow. Please bear with me if I am doing it wrong.
I am working on a ruby on rails application and had to change the source code of a gem I am using in
/Users/username/.rvm/gems/ruby-2.0.0-p353/gems/gemname-4.1.0.
This works well and I make a fork of the gem on github, applied the changes I made, pushed, and change my gemfile line from
gem 'gemname'
to
gem 'gemname',:git=>"git#github.com:/name/gemname.git"
I run bundle install again and now the changes made are not applied to my application anymore.
When I do bundle show 'gemname' I saw the gem is install in
/Users/username/.rvm/gems/ruby-2.0.0-p353/bundler/gems/gemname-a0ed76fc98e2
I am not an expert on how bundle and github works. If anymore could explain how they work and what I should do to use my own forked version of the gem in my application, it would be very help!
Thanks in advance!
you could also write:
gem 'gemname', 'git://github.com/name/gem_name.git
or:
gem 'gemname', github: 'name/gem_name'
also be sure that you have your changes in master, and restarted your server after bundle
I ended up doing,
gem 'gemname',:git => "git#github.com:/myname/gemname.git", :branch => '1.1'
and it works fine now.
I think the problem is that I need to specify the branch 1.1 which is my branch, otherwise it uses the master's branch which my changes are not applied.

Error launching Rails server: undefined method 'configure'

I'm new to rails and working through Hartl's tutorial. Everything was fine until I tried to do the tutorial a second time and created another project trying to use the latest version of rails. When I try to load the rails server from the app folder I get the following error.
$ rails s
=> Booting WEBrick
=> Rails 4.0.4 application starting in development on
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/sierra/Desktop/sample_app_2/config/environments/development.rb:1:in
`<top (required)>': undefined method `configure' for
#<SampleApp2::Application:0x00000101a74610> (NoMethodError)
My Gemfile is directly from the Hartl tutorial:
source 'https://rubygems.org'
ruby '2.1.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.4'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor', '0.0.2'
end
I resolved it by doing following step.
Step 1: go to Project_Root_Directory/config/environment/development.rb
Change this line
Rails.application.configure do
To
Your_Rails_Application_Folder_name::Application.configure do
For example my rails project folder name is 'Spree_demo' so Your_Rails_Application_Folder_name in the following line:
Your_Rails_Application_Folder_name::Application.configure do
will be replaced as
SpreeDemo::Application.configure do
Note: See underscore in your application folder name it gets removed.
Hope it works for you guys.
First set Ruby version before Rails new
I had the same problem and I tried the answer given and it had no impact.
I even tried changing the name to get rid of the underscore, and it had no impact.
The problem is that you did this:
$ rails new app_name
But your ruby version was probably 2.1.1 or something else. You want to do:
$ rvm 2.0.0
BEFORE you run the new app, and then when you set 2.0.0 in your Gemfile (as Hartl recommends) it falls into place.
I don't know WHY this works, and I hope someone will shed light on it, but I can tell you that this worked better than the answer that is currently in the lead.
That happened to me too. The problem was that I used one version of Rails to create the project. Then I changed the Gemfile to use another version of Rails and the system was using it to scaffold or run the server. Newbie problem!
Using the same version consistently should solve the problem. :-)
I posted a (probably way too long) answer in a similar question: rails - NoMethodError: undefined method `configure' for FirstApp. This thread actually started me on the way to my eventual solution, so I thought I'd post here as well just in case it's helpful to anyone else.
From what I can tell, the problem occurs when the app/config/initializers/development.rb (and production.rb) files are generated for a new project using some newer versions of Rails (I'm not sure in which version it started, I only tested Rails 4.1.4). Mr. Hartl uses Rails 4.0.8 for his tutorial, and that's the highest version I tested in which the new syntax doesn't occur.
In Rails 4.1.4, and maybe some other versions after 4.0.8, the first line in those files is generated as Rails.application.configure.do rather than, using a project called sample_app as an example, SampleApp::Application.configure.do as in 4.0.8.
I'm new to Rails so I don't know why this syntax changed in newer versions. I'm assuming it's intentional and somehow better than the old way. Most likely, Mr. Hartl will take it in to account in future editions of his tutorial that are updated for versions of Rails which include this change.
Until then, see my other answer in the question I mentioned above for a more thorough explanation of how I got around it on Windows 7, but the tl;dr of it is:
Make sure you're using the version of Rails specified for the tutorial (4.0.8) in your local repository/root development directory before you create your new project. Updating your Gemfile after creating the project is still important, but it won't solve this problem if the files themselves were generated with a newer version of Rails. You'll have to go in and edit that line manually in that case, as other users have suggested.
I had this issue when I messed around with my Gemfile. For example I have created the app using rails 4.0.2 or something like that then due to some errors I changed it to 4.1.1 that change cause this exact same problem in both development and production

How to get an application to use a local branch version of Ruby on Rails

Let's say I want to add some new features to Rails. According to the Rails Guide on how to contribute to Rails, I should clone the main repository, create a branch, then make my changes in that branch.
My question is: after I've done all of that, how do I go about testing my changes in an actual Rails application? That is, how do I get a Rails application running on my machine to use the Rails code from my branch rather than the Rails code installed on my system?
The simplest approach I can think of is to simply replace the "rails" folder in my gems folder with the code from my branch, but it seems like there should be a cleaner way to do this.
If you're using bundler, just point to your modified version in your Gemfile by specifying either the path of the gem on the filesystem or your forked git repo. Like this:
gem 'rails', :path => '/full/path/to/mofidied/rails'
or for git:
gem 'rails', :git => git://github.com/github_user/your_rails.git
If you change the minor revision number and install it in your gems folder you can specify that new version when you create a new app
rails _3.0.x_ new newappname

Implemented Rails 3, but "rails -v" is still 2.3.10?

I can see the rails 3 gem from gem list. But why the rails -v still tell 2.3.10? What should I do to update it?
In your Gemfile for your project, just specify :
gem 'rails', '3.0.3'
And you are good to go :)
If you have multiple versions of rails showin in gem list, you can call a specific one by passing the version as the first argument:
$ rails _2.3.5_

Resources