Easing the pain of transition to Rails 4

2.1k views Asked by At

I am working on a Rails 3.2 application now, but I am aware that Rails 4 is just around the corner. What are the things I should be aware of now when implementing my application to make it easier to migrate to Rails 4 when it is formally released or perhaps after the couple of point releases? I know that some of the functionality will be spun out into gems, but then there is no guarantee of support in Rails 4.1+.

I have read the upgrade guide: http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0, and the release notes: http://edgeguides.rubyonrails.org/4_0_release_notes.html.

I am more interested in this point to identify the gotchas that would cause me headaches in an upgrade, rather than the nice new shiny features of Rails 4.

So based on this reading and snippets from the Internet, what I have at the moment is:

  • Upgrade to Ruby 1.9.3 at a minimum.
  • Don't use plugins - use gems instead.
  • ActiveRecord::IdentityMap will not be in Rails 4.
  • ActiveResource will not be part of core Rails 4, but will be in a separate gem (activeresource). Possibly consider other ORMs for REST APIs.
  • Do not use Dynamic Finder Methods in ActiveRecord like find_all_by_* or scoped_by_* as these will be deprecated. Use where instead.
  • Avoid Hash-based Finders: e.g. User.find(:all, :conditions => ... and use where instead.
  • Eager Evaluated Scope in ActiveRecord: scope will require a lambda. E.g. use scope :red, -> { where(color: 'red') } not scope :red, where(color: 'red').
  • ActiveRecord::SessionStore will now be a separate gem (activerecord-session_store).
  • Use ActiveSupport::Logger instead of BufferedLogger.
  • Start using the strong_parameters gem in anticipation of Strong Parameters in Rails 4. Instead of attr_accessor, attr_accessible, attr_protected at the ActiveRecord level, this involves putting params.require into the controller to force the correct parameters to be supplied.

...but I'm sure there is more. Could anyone provide a comprehensive but common-sense list to be aware of? I'm not looking for a full list of deprecations in Rails 4 - it's the big things to be aware of and what I can do now to future-proof for them.

0

There are 0 answers