#415 Upgrading to Rails 4
May 06, 2013 | 12 minutes | Rails 4.0
With the release of Rails 4.0.0.rc1 it's time to try it out and report any bugs. Here I walk you through the steps to upgrade a Rails 3.2 application to Rails 4.
- Download:
- source codeProject Files in Zip (63.4 KB)
- mp4Full Size H.264 Video (35.6 MB)
- m4vSmaller H.264 Video (17.7 MB)
- webmFull Size VP8 Video (18.6 MB)
- ogvFull Size Theora Video (46.4 MB)
Resources
- Rails 4.0: Release Candidate 1 released!
- Episode 400: What's New in Rails 4
- Episode 371: Strong Parameters
- Episode 321: HTTP Caching
- Episodes on Rails 4.0
terminal
git checkout -b rails4 bundle update bundle outdated rspec .
Gemfile
gem 'rails', '4.0.0.rc1' gem 'sqlite3' gem 'sass-rails', '~> 4.0.0.rc1' gem 'coffee-rails', '~> 4.0.0' gem 'uglifier', '>= 1.3.0' gem 'jquery-rails' gem 'paper_trail', github: 'airblade/paper_trail', branch: 'rails4' # add these gems to help with the transition: gem 'protected_attributes' gem 'rails-observers' gem 'actionpack-page_caching' gem 'actionpack-action_caching'
config/application.rb
Bundler.require(:default, Rails.env) # Remove: # config.active_record.whitelist_attributes = false # config.assets.enabled = true
config/routes.rb
patch :update_many # ... get 'new', to: 'episodes#new'
config/development.rb
config.eager_load = false # Remove: # config.whiny_nils = true # config.action_dispatch.best_standards_support = :builtin # config.active_record.mass_assignment_sanitizer = :strict # config.active_record.auto_explain_threshold_in_seconds = 0.5 # config.assets.compress = false
config/production.rb
config.eager_load = true config.assets.js_compressor = :uglifier
config/test.rb
config.eager_load = false # Remove: # config.whiny_nils = true # config.active_record.mass_assignment_sanitizer = :strict
config/initializers/secret_token.rb
Screencaster::Application.config.secret_token = '...' Screencaster::Application.config.secret_key_base = '...'
models/episode.rb
scope :published, -> { where('published_on <= ?', Time.now.to_date) }
episodes_controller.rb
before_action :load_episode, only: [:show, :edit, :update, :destroy] private def episode_params params.require(:episode).permit(:description, :name, :seconds, :published_on, :timecode) end