The following is a list of changes that aren't necessarily documented / useful to have a reference for.
Be sure you've read the official guides and release notes.
Also review the CHANGELOG
s in the GitHub repository.
Recommended changes before upgrading. These are not necessary, but can be made while still on Rails 3.2 and will ease the amount of work required to upgrade.
- Review your dependencies on http://www.ready4rails4.net/
- Switch to using the
strong_parameters
gem prepare for the removal ofattr_accessible
and/orattr_protected
.attr_accessible
andattr_protected
have been extracted to a gem if this isn't feasible. - Update to the latest version of
simple_form
. This will require removing all HTML markup fromsimple_form
's i18n file. You will still have to updatesimple_form
as part of the Rails update process, but you won't have to deal with HTML markup in i18n for labels. - Update to the latest version of
devise
so you'll havestrong_parameters
support out of the box. Also forces you to deal with some of the upstream changes made todevise
separately from updating Rails. - Ensure you're using the latest
database_cleaner
gem to include the following fix: DatabaseCleaner/database_cleaner#253
- Switch
[asset-type]-url
helpers in anysass
files toasset-url('file', [asset-type])
. - Add
vendor/images
to precompile path - Remove
:assets
group from Gemfile and removeRAILS_GROUP
functionality fromBundler.require
inconfig/application.rb
. NOTE: To avoid bloating you application start-up time, consider vendoring assets that are provided as-is by a gem without additional functionality.
- Use multi-line anchors for regular expressions when using the
ActiveModel
:format
validator.
- Use
to_a
when you want anArray
instead of anActiveRecord::Relation
. - Wrap all relations passed to
scope
in alambda
.
- Specify
config.eager_load
in all environments. - Use http://railsdiff.org/ to review upcoming changes to the code generated
by
rails new
to see any additional configuration changes that may affect you.
Changes to make after updating to Rails 4. The above changes are all included if you didn't make them before updating.
- Remove version requirements for
sass-rails
,coffee-rails
anduglifier
- If using
haml
, usehaml-rails
to correclty configurecache_digests
- Remove
strong_parameters
,cache_digests
andsextant
from theGemfile
if present.
- Switch all
-url
sass
helpers to beasset-url('file.ext')
.
- Specify compressors for CSS and JavaScript.
# remove
config.assets.compress = true
# add
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
- Convert
db/schema.rb
to use 1.9 hash syntax usingrake db:schema:dump
. This makes commits for the first migration under Rails 4 readable since it won't include coverting the syntax of the schema file.
- In controllers, use
(before|after)_action
instead of(before|after)_filter
- Switch to
Model#update
overModel#update_attributes
- Use
Model.all
instead ofModel.scoped
.