Pragmatic – Leading provider of open source business applications OpenERP, Ruby on Rails, Node.js, Talend, jaspersoft  – Pragmatic
Beyonce Adams

Rails 4

Rails just keeps on changing. Both Rails 3 and 4, as well as Ruby 1.9 and 2.0, bring hundreds of improvements, including new APIs and substantial performance enhancements. The fourth edition of this award-winning classic has been reorganized and refocused so it’s more useful than ever before for developers new to Ruby and Rails.

Rails 4 will only support Ruby 1.9.3+ versions.

Upgrading from Rails 3.2 to Rails 4.0 : 

If you want to upgrade your rails 3 application in rails 4, then you need to do changes in your rails application. If your application is currently on any version of Rails older than 3.2.x, you should upgrade to Rails 3.2 before attempting one to Rails 4.0 and do the changes in… 

Gemfile : 

Rails 4.0 removed the assets group from Gemfile. You’d need to remove that line from your Gemfile when upgrading. In Rails 4.0, several features have been extracted into gems. You just add the extracted gems to your Gemfile to bring the functionality back.     

  • Hash-based & Dynamic finder methods
  • Mass assignment protection in Active Record models.
  • ActiveRecord::SessionStore
  • Active Record Observers
  • Active Resource
  • Action Caching
  • Page Caching
  • Sprockets
  • Performance tests

Action Mailer : 
No changes  

Action Support: 
Rails 4.0 removes the j alias for ERB::Util#json_escape since j is already used for ActionView::Helpers::JavaScriptHelper#escape_javascript. 

Action Pack:
 Rails 4.0 introduces ActiveSupport::KeyGenerator and uses this as a base from which to generate and verify signed cookies. Existing signed cookies generated with Rails 3.x will be transparently upgraded if you leave your existing secret_token in place and add the new secret_key_base. 
 # config/initializers/secret_token.rb
Myapp::Application.config.secret_token = ‘existing secret token’
Myapp::Application.config.secret_key_base = ‘new secret key base’ 

vendor/plugins:
Rails 4.0 no longer supports loading plugins from vendor/plugins. You must replace any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, lib/my_plugin/* and add an appropriate initializer in config/initializers/my_plugin.rb.
 

Active Record:
Rails 4.0 has removed the identity map from Active Record, If you have manually enabled it in your application, you will have to remove the following config that has no effect anymore: config.active_record.identity_map.


The delete method in collection associations can now receive Fixnum or String arguments as record ids, besides records, pretty much like the destroy method does. Previously it raised ActiveRecord::AssociationTypeMismatch for such arguments. From Rails 4.0 on delete automatically tries to find the records matching the given ids before deleting them


Rails 4.0 has removed attr_accessible and attr_protected feature in favor of Strong Parameters. You can use the Protected Attributes gem to a smoothly upgrade path.


Rails 4.0 requires that scopes use a callable object such as a Proc or lambda:
scope:active,where(active: true)
#becomes
scope:active,->{where active: true}
 

Active Model:
Rails 4.0 has changed how errors attach with the ActiveModel::Validations::ConfirmationValidator. Now when confirmation validations fail, the error will be attached to :#{attribute}_confirmation instead of attribute.

Active Resource:
Rails 4.0 extracted Active Resource to its own gem.
 

Sprockets-rails :
assets:precompile:primary has been removed. Use assets:precompile instead.
 

Sass-rails:
asset_url with two arguments is deprecated. For example: asseurl(“rails.png”, image) becomes asset-url(“rails.png”)

Executables:
The script directory has been removed in favor of a new bin directory. This is where your app’s executables will live, and running rake rails:update:bin will put bundle, rake, and rails binstubs into your app’s bin directory. This change can be useful in development, especially on a machine with multiple Ruby versions and gems. You can use bin/rails instead of bundle exec rails to ensure you run your executables in the correct environment.

Leave a Reply

Subscribe to Blog via Email.

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Related Posts