Welcome to End Point’s blog

Ongoing observations by End Point people

Rails 4 Highlights

I watched this recent video What to Expect in Rails 4.0 presented by Prem Sichanugrist to the Boston Ruby Group. Here are a few high-level topics he covered in the talk:

  • StrongParameters: replaces attr_accessor, attr_protected, moves param filtering concern to the controller rather than the model. Moving param filtering concern to the controller allows you to more easily modify user attribute change-ability in controllers (e.g. customer-facing vs admin).
  • ActiveSupport::Queue: Discussed at RailsConf, add queueing support to Rails, e.g.:
    # Add to queue
    Rails.queue.push UserRegistrationMailerJob(
    # Control queue configuration (asynchronous, synchronous or resque, e.g.
    config.queue = [:asynchronous, :synchronous, :resque]
  • Cache Digests: Rails 4.0 introduces cache key generation based on an item and its dependencies, so nested cache elements properly expire when an item is updated.
  • PATCH verb support: Support of HTTP PATCH method (_method equals "patch"), which will map to your update action is introduced in Rails 4.0.
  • Routing Concern: Rails 4.0 introduces some methods to help clean up your duplicate routes.
  • Improvements to ActiveRecord::Relation
    • Relation.all: returns ActiveRecord::relation object. User.all => User.to_a
    • Relation.none: Returns ActiveRecord::NullRelation, still chainable
    • Relation.___!: mutates current relation, e.g. @users.where!, @users.include!
  • Deprecations
    • AR::Base.scoped
    • Dynamic Finder Methods: e.g. find_all_by_*
    • Hash-based Finders: e.g. User.find(:first)
    • Eager Evaluated Scope: scope will require a lambda
    • ActiveRecord::SessionStore
    • ActiveResource
    • Rails::Plugin
  • New Deprecation Policy: Many of the above deprecations will still work in Rails 4.0 and included as gem dependencies, but will be removed in the jump to Rails 4.1. This means that the upgrade to Rails 4.1 may be more painful than the upgrade to Rails 4.0.

Check out the video or read the official current Rails 4.0 release notes here. Also, check out this post I came across about PostgreSQL array support in Rails 4, which may be pretty interesting to our PostgreSQL experts.


Anonymous said...

Rails 4 will surely be as great as the 3.0. I just hope less hard to migrate

But the real question is: when should we expect rails 4?

Steph Skardal said...

Hi Anonymous,

The video briefly touches on when this will be out. It mentions that a release candidate may be out by the end of the year. Speaking from my personal experience with the Rails 3 cycle, I think it'll be much longer before it's official release and then a bit longer after that until it picks up steam. And the article notes that the real upgrade happens from 4.0 to 4.1, so that extend the timeline further. I wouldn't hold my breath, but it is interesting to see where the technology is headed.


Rind said...

You mean attr_accessible instead of attr_accessor?

Steph Skardal said...

attr_accessor is a direct quote from the video, but I think that strong parameters replaces both of the mass assignment methods.