Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Upgrading Rails Application From 3.0 to 3.1

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 650
    Comment on it


    Upgrading a rails application directly from a lower version to a much higher version is never a good idea, so the best idea is to do it step by step. like one upgradation at a time. In my previous blog Things to Notice Before Upgrading Rails Application. I explained about the guidelines for updating. Here I am going to tell you how we can upgrade our rails application from 3.0 to 3.1. These are following things that you need to take care of before upgrading:


    1) Inside the Gemfile update the rails version:

    # This is the last rails version of 3.1.x series
    gem 'rails', '3.1.12'


    2) Gems for asset pipelines also needs to be updated to something like this:

    group :assets do
      gem 'sass-rails',   '~> 3.1.7'
      gem 'coffee-rails', '~> 3.1.1'
      gem 'uglifier',     '>= 1.0.3'
    end


    3) Now we need to add the default javascript library for rails 3.1, which is jquery-rails, so add this also to your Gemfile

    
    gem 'jquery-rails'

    4) The major change occured from rails 3.0 to 3.1 was the change in assets, so that also requires change in the application.rb to include the following things:

    
    config.assets.enabled = true
    config.assets.version = '1.0'
    

    5) For the applications which are using '\assets' routes, they needed to change the prefix for assets path, to avoid any kind of conflicts:

    
    # Defaults to '/assets'
    config.assets.prefix = '/your-assets-path'


    6) Again as I was already saying, the major change in rails 3.1 is regarding assets so again inside your environment/production.rb, you need to add following things:

    # Compress JavaScripts and CSS
    config.assets.compress = true
     
    # Don't fallback to assets pipeline if a precompiled asset is missed
    config.assets.compile = false
     
    # Generate digests for assets URLs
    config.assets.digest = true
     
    # Defaults to Rails.root.join("public/assets")
    # config.assets.manifest = your-path
     
    # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
    # config.assets.precompile += %w( any-additional-js any-additional-css )
     
    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
    # Depends on your application requirement
    # config.force_ssl = true
    

    7) Test performances can also be improved by adding the following into your environment/test.rb:

    # Configure static asset server for tests with Cache-Control for performance
    config.public_file_server.enabled = true
    config.public_file_server.headers = {
      'Cache-Control' => 'public, max-age=3600'
    }
    


    8) If you want to wrap parameters into a nested hash, you can add an initializer to do that. This gets by default added if you create a new application in rails 3.1 or 3.1+

    # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
    ActiveSupport.on_load(:action_controller) do
      wrap_parameters format: [:json]
    end
     
    # Disable root element in JSON by default.
    ActiveSupport.on_load(:active_record) do
      self.include_root_in_json = false
    end
    

    9) One more change needed in initializers, this time it is related to sessions, so you need to change the session key to something new or remove all the existing sessions so do change in config/initializers/session_store.rb :

    # in config/initializers/session_store.rb
    AppName::Application.config.session_store :cookie_store, key: 'NEW_KEY'
    
    or
    
    > rake db:sessions:clear
    

    10) Now at last :cache and :concat have been removed in rails 3.1, So delete these option if they are available in your views:


    Thus those were the necessary changes required to update an application from rails 3.0 to 3.1. Now run your test cases to check whether you are successfully upgraded or not.

    Hope you liked this blog.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: