How do I update rails to 4.2? - ruby-on-rails

How do I update rails to 4.2?
I googled it.I have read 3 or 4 so questions about it. But I am confused still. May be because I am new to rails.
Right now I got that the best way is just to specify rails version in my gem file.
Update my rails version
jonstark#jonstark-pc:~/rails_projects$ rails -v
Rails 4.0.3
And I want to make latest uptodate rails version default

It depends on your Rails version. In your case it hasn't changed that much on the app side from 4.0.3 to 4.2.5.1. Nonetheless I would recommend you to run the update script of rails afterwards.
Important! Don't forget to commit. Before and after.
Step 1:
Update Rails in your Gemfile:
gem 'rails', '4.2.5.1'
Run bundle update.
Step 2:
Run the update script:
$ rake rails:update
Be careful! It asks you to override a lot of config files. Check the changes and decide if the changes are necessary.
Step 3:
Check your Gems if all of them are compatible.
Here also an Upgrading Guide from the Rails Guides.

Edit your Gemfile, change the existing rails specification:
gem 'rails', '~> 4.2', '>= 4.2.5'
Run bundle update rails

Related

Specifying rails version to use when creating an api (rails-api)

I would like to create a rails-api with a specific version number for rails (i.e. 4.0.5) I would like to know how to proceed through the command line. Up to now I proceeding as if I would have to specify a rails version for an app but I'm getting some obvious error that it's not the way to proceed
rails-api _4.0.5_ new application_name -d mysql
error
Could not find 'rails-api' (= 4.0.5) - did find: [rails-api-0.2.1] (Gem::LoadError)
I think you need to install rails the standard way:
gem install rails -v=4.0.5
I am not familiar with rails-api but looks like it will only accept the rails-api version as a parameter, not rails itself. If it creates a rails app itself, it will certainly create a Gemfile. You could always change the rails version in the gemfile later and run bundle again:
gem 'rails', '4.0.5'
And run
bundle install

Can I change the expected Rails version of a Rails application?

I downloaded an archive containing code for a Rails application ( from a book I'm reading ). I'm running Rails 3.0.1 but the application fails to start, because it's looking for 3.0.0beta3. Is there some way of starting it with my version of Rails?
Yes, look for the Gem file in the application root and look for the line
gem 'rails', '3.0.0beta3' and change it to
gem 'rails', '3.0.1'
then run bundle install from a terminal in your application root.
this is because your Gemfile.lock is probably showing Rails 3.0.0.beta3. Even if you change your Gemfile to 3.0.1 AND install it using gem install rails, you will need to run bundle install or bundle update rails
There is probably a line in the environment.rb file that looks like
RAILS_GEM_VERSION = '3.0.0beta3' unless defined? RAILS_GEM_VERSION
Updating this should sort your issue.

How can I install different versions of Rails and keep the existing ones?

I had Rails 2.3.5 installed, and wanted to upgrade to 2.3.10 as a stepping stone to Rails 3. I thought running gem install rails -v=2.3.10 would install 2.3.10 and keep 2.3.5 as well. But now when I do rails -v, it only lists Rails 2.3.10. How can I install different versions of Rails and keep the existing ones?
gem list rails should show you all installed versions of Rails. You can specify which one you want each project to use in the config/environment.rb file.
Alternately (or "additionally"), look in to RVM (particularly the "gemset" function) for maintaining separate gem sets for each project.
Updated May 2017 Instead of RVM gemsets, best practice for managing gems in Rails projects (including the Rails gem itself) is to use Bundler. Bundler's Gemfile will list all the gems your project uses, and allows you to "pin" versions, so by changing the version pin for Rails and running bundle you can update your project to the new version.
<sarcasm>Now that I've said that, though, Bundler is probably on the way out to be replaced by something else. </sarcasm>
You still have both versions, as the other answers have mentioned. However, you don't want to call rails newapp and then change the config/environment.rb file. This will cause problems for any files that have changed between versions. Instead, create a new 2.3.5 app this way:
rails _2.3.5_ newapp
And you'll run the exact version of rails you want, to create the file structure correctly. I don't know why this isn't documented better.
To answer your question, you can install many versions of the rails gem without conflict. However, each project is created using a specific version. To install a new version of the rails gem as follow;
Change the version 3.2.18 with any version you like (see link below for all available versions).
gem install rails --version=3.2.18
To install the latest version
gem install rails
To check all the rails version available, check out this link
Here is a link to all the version of rails
You might consider updating your gem software by this command prior to loading new gems.
gem update --system
As per #pjmorse, list the version installed with this command
gem list rails
Hope that helps
You can define the Rails version of an application in config/enviroment.rb.
You can vendor the version of rails you want into your vendor/rails folder. At the command line just run rake `rake rails:freeze:edge RELEASE=2.2.2'. You don't need any version of rails installed for this to work it will take the source and build it from the remote source in your vendor directory.
rake rails:freeze:edge RELEASE=2.2.1
rake rails:freeze:edge RELEASE=2.2.2
rake rails:freeze:edge RELEASE=2.2.3
rake rails:freeze:edge RELEASE=2.2.4
rake rails:freeze:edge RELEASE=2.2.5
rake rails:freeze:edge RELEASE=2.2.6
rake rails:freeze:edge RELEASE=2.2.7
rake rails:freeze:edge RELEASE=2.2.8

How to use the Rails 2.3 app generator when I have Rails 3 installed?

to clarify: there's only one rails command, which gets installed from the latest Rails gem, which is Rails 3 ATM. However, I'm required to create a Rails 2.3 app.
Running ruby /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.8/bin/rails fails with a NoMethodError, I suppose because it also tries to use gems from the 3.0.0 release.
Uninstalling the gem produces some strange results:
$ gem uninstall rails-3.0.0
ERROR: While executing gem ... (Gem::InstallError)
cannot uninstall, check `gem list -d rails-3.0.0`
$ gem list -d rails-3.0.0
*** LOCAL GEMS ***
(and no gems here)
What should I do?
The easiest way to do it was:
Create the directory for the project
Create a Gemfile there containing
gem "rails", "2.3.9"
gem "sqlite3-ruby", :require => "sqlite3"
Run bundle install
Run bundle exec rails . to create an app in the current path
You don't even need rvm to do this.
(I assume 2.3.11, given it's the latest)
rails _2.3.11_ new app will do this for you without you having to muck about.
(Had to make a comment since I don't have enough Stack Overflow cred and can't directly respond to answers yet.)
For folks running rails 3 now the "new" command is now required for creating new rails applications. As such "new" will need to be appended to the end of the commands.
So for Leonid Shevtsov's answer, Step 4: bundle exec rails new .
And for Robert Speicher's answer: rails new .
Install rvm and then create a new gemset, so that Rails 2 is isolated.
Or, go to the directory where you want your Rails 2 app to be, create a Gemfile like a Rails 3 app, but specify gem "rails", "~> 2.3" and run bundle install, and you should now be able to issue rails .

How can my Rails app accept RAILS_GEM_VERSION minor version bumps

My rails project has this line in /config/environment.rb
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
As we now have 2.3.5 as the most recent upgrade, is there a way to make my environment.rb accept minor version bumps?
(without I have to explicitly change 2.3.2 to 2.3.5)
No, there isn't.
You application needs to use a specific Rails version mostly because different tiny releases might require additional steps to upgrade the framework such as changes to boot.rb.
$ rake rails:update
Things have evolved a bit since Rails 2, so Ill share what I had to do to get from 5.0.0 to 5.0.0.1 today.
My Gemfile read gem 'rails', '~> 5.0.0'. I figured that was enough, but bundle install was not updating anything new. So I tried to force it with gem 'rails', '~> 5.0' which also did nothing new when I ran update (note: this is for an experimental app of my own, and not someone else's app I am working on - don't just default to allowing minor version updates to solve problems like this ;) ). So I had to try a few other ways to force this security patch/hotfix.
First, I had to install the package locally:
gem install rails --version 5.0.0.1
Next, I updated bundler:
bundle install
...and I saw this in the output: Using rails 5.0.0.1 (was 5.0.0)
When I ran ./bin/rake rails:update, it wiped the contents of my config/routes.rb file, changed many of my settings in various config files (some of which were dangerous security settings to change), among a few other seemingly benign changes. While this is the expected behavior, I am pointing this out as not exactly a desirable method for updating a minor patch/hotfix for rails.
Firstly, you need to change the version to 2.3.5 from 2.3.5 and then run
rake rails:update

Resources