Thursday 29 August 2013

Getting Started with Ruby 2 and Rails 4


If you are new to Rails then you will might want to check out my other post basic installation packages as the following steps will assume a similar setup.

Installing Ruby 2
  • Ruby 2 is the latest stable version to start working with it.
  • rvm install ruby-2.0.0
  • rvm list
  • rvm use ruby-2.0.0-p247
Installing Rails 4

Before installing a new version of Rails, I like to switch to a new RVM gemset. If you're not using RVM, don't worry about this step. 
A Best Rails 4 Book to start with
$ rvm use @rails4 --create
Installing Rails 4 is as easy as it ever way, just use gem install.
            gem install rails -v=4.0.0.rc2
Rails 4 is now the latest stable release so it's much easier to get going with it. 
Once the gem installer has done it's thing you can now check the Rails version withrails -v and start a new project in the usual way.








How to create a Rails 3 project with Rails 4 installed
With Rails 4 now taking priority over Rails 3 in your gem list how do you make a new Rails 3.2 project without going through the hassle of uninstalling Rails 4.
Simple really, check the versions of Rails you have installed already with gem list rails.
*** LOCAL GEMS ***
rails (4.0.0, 3.2.13)
The output shows I have the Rails 4.0.0 and 3.2.13 installed and you can simply append that version number to your rails command like so.
rails _3.2.13_ new myproject
This will create a project in the usual way but this time using the 3.2.13 version of the gem.
Don't forget that you should use bundle exec within your project when callingrails generate and friends so that the correct gem version according to the projects Gemfile is used. For example: bundle exec rails generate model User.

No comments: