Notes on upgrading from Rails 4.1 to 4.2
Posted on January 21st, 2015
This one is a fairly easy upgrade although it was a little hard to discover all the issues. The main work was around removing Inherited Resources.
Here are more detailed notes:
- All calls to
.deliver_now. Including in your tests and stubs. If you had any tests that depended on the code block to be executed, you have to call
.deliver_nowas method execution has been made lazy.
- The configuration
config.serve_static_assetsis now renamed to
application.rbor appropriate environment file.
- Inherited Resources is no longer compatible with rails 4.2 (simply due to gem spec constraints but still). Removing it is tedious but not very hard. It’s a matter of changing any
actionscall in your
InheritedResourcecontrollers to actually implement the method. I actually cleaned a lot of filters along with those changes. Overall, I regret having used Inherited Resources in the first place. The laziness of not writing a few simple actions was surely not worth it.
- Add the responders gem to your Gemfile if you used
respond_toon class level controller and
respond_withwithin controller actions.
- I18n was upgraded as part of Rails 4.2. With the upgrade, assigned locales are now enforced to be in the list of available locales. Rails supports this by allow you to configure i18n in the
Current::Applicationclass. Just add
config.i18n.available_locales = [:en, :your_locale].
However, if you are using Guard-Konacha, it’ll try to load your rails configurations but will not consider this configuration. As a result, you are forced to add
I18n.available_locales = [:en, :your_locale]at the top of the application.rb file (and not inside the
Current::Applicationclass). Check this issue for more details.
- State Machine is broken. More even than in Rails 4.1. Now my
config/initializers/state_machine.rbis even bigger. I used a version of the code available in this gist.
- FactoryGirl causes
existsto be called on the real
ActiveRecordobject instead of using
.idso you get a warning like:
DEPRECATION WARNING: You are passing an instance of ActiveRecord::Base to `exists?`. Please pass the id of the object by calling '.id’.
I just left that one in there and decided to update FactoryGirl when a version higher than 4.5.0 comes out.
- Formtastic will call
column_for_attributefor each input in the form. This can cause the following warning to show up:
DEPRECATION WARNING: ‘#column_for_attribute' will return a null object for non-existent columns in Rails 5.
Use '#has_attribute?' if you need to check for an attribute's existence.
It means some of the attributes in your form is not in your model. This can happen if you use some confirmation (like password_confirmation) or have a helper (like tags separated by comma). Rails used to be fooled if you just created an
attr_accessorfor that attribute but that trick no longer works. This will need an update in formtastic (probably coming in version 4.x).
I left this warning showing as well in hopes of either moving out of Formtastic or upgrade it when the new version comes out.