From 0 to 60 with Rails 4.0
Jun 25, 2013 - Elliott Draper
Now that Rails 4.0 has been released (and Heroku have announced that all new Ruby apps default to Ruby 2.0!), let’s take a look at just how easy it is to get up to speed with the latest Ruby and Rails versions, so that we’re using the most up-to-date tech for starting new apps.
To get up and running quickly with Ruby 2 and Rails 4.0 (using RVM), it’s really pretty easy:
rvm get stable rvm install 2.0.0 rvm use 2.0.0 rvm gemset use rails4 --create gem install bundler gem install rails
And then when the gems are installed, you can create a new app using Rails 4.0:
rails new my_rails4_app
Once that’s all installed, you can get to grips with the latest changes in Rails 4.0 - but what are those changes?
A lot of refactoring has gone on, with Active Record made more consistent, and more secure by default. Active Resource, Active Record observers, and Action Pack page and action caching have all been moved out of the core Rails framework and into their own gems.
Rails 4.0 has support for live streaming for persistent connections, and is now safe for threaded web servers by default. It also has a focus on making your user interfaces super snappy, with new caching techniques, declarative etags to ensure you’re using all that HTTP has to offer, and the much talked about Turbolinks, turning your app into a single page app by making all links load using AJAX automatically. This focus doesn’t detract from Rails being a great choice for JSON APIs for client side frameworks like Ember.js and Backbone.js though.
You can read more about the changes on the official Rails 4.0 release post.
Upgrading from Rails 3.2
In terms of upgrading existing Rails apps, you’ll want to make sure you’re on Rails 3.2 first, before attempting the jump to 4.0. From there, the biggest things that’ll probably trip you up are the removal of attraccessible and attrprotected, scopes changing to require a callable object (Proc or lambda), and Active Model Serializers no longer including the root element in output JSON.
You can read the full list of things to consider when upgrading here.
Go forth and build with the latest and greatest Rails has to offer - remember, we’ve been doing Rails for 7 years now, so if you have any questions about the upgrade, or need an expert to help, get in touch!
blog comments powered by Disqus
Back to blog