#282 Upgrading to Rails 3.1
Sep 05, 2011 | 8 minutes | Rails 3.1
It is incredibly easy to upgrade to Rails 3.1, but if you want to take advantage of the asset pipeline you will need to put in some extra effort. Have no fear because I walk you through each of the necessary steps in this episode.
Resources
Gemfile
gem "rails", "3.1.0" # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', " ~> 3.1.0" gem 'coffee-rails', "~> 3.1.0" gem 'uglifier' end gem 'jquery-rails'
config/application.rb
if defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require *Rails.groups(:assets => %w(development test)) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end # ... # Enable the asset pipeline config.assets.enabled = true # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0'
config/environments/development.rb
# comment out this line: # config.action_view.debug_rjs = true # Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true
config/environments/test.rb
# Configure static asset server for tests with Cache-Control for performance config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" # This config option was shown in the episode but is actually not used, so don't bother adding it. # config.assets.allow_debugging = true
config/environments/production.rb
# 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
views/layouts/application.html.erb
<%= stylesheet_link_tag "application" %> <%= javascript_include_tag "application" %>
.gitignore
.sass-cache/
app/assets/javascripts/application.js
//= require jquery //= require jquery_ujs //= require_self //= require_tree .
app/assets/stylesheets/application.css
/* *= require_self *= require_tree . */
Don't forget to move all of your assets into app/assets and replace any static references to them with helper methods (such as image_tag
).