Upgrading to Rails 5.1x

  • Yarn and webpack support
  • Dropped JQuery as a default dependency
  • Built-in support for writing system tests using Capybara
  • Encrypted secrets
  • and many more, you can find the detailed release notes here. Recently we upgraded one of our production apps to 5.1x and since we have good test coverage, upgrading was mostly painless. We still had to make some minor changes down the road

    1. No more before_filter

    One of our controllers still had the old-fashioned `before_filter` and we encountered the following error while booting up

    undefined method 'before_filter' before_filter has been deprecated in Rails 5.0 and removed in 5.1.

    This is because `before_filter` and after_filter are deprecated from Rails 5.0.0 onwards. As you might have guessed, changing from before_filter to before_action is the solution here.  

    2. halt_callback_chains_on_return_false is deprecated

    We saw the following deprecation warning in our logs after the update

    ActiveSupport.halt_callback_chains_on_return_false= is deprecated and will be removed in Rails 5.2.

    From Rails 5.0x, the callback chain is not halted when a before callback returns false. We need to use throw(:abort) to explicitly halt callbacks Though we had no return false in our callbacks, we still had to remove the line, ActiveSupport.halt_callback_chains_on_return_false = false from config/initializers/new_framework_defaults.rb to get rid of the warning.  

    3. Passing a class to the class_name is deprecated

    One of the deprecation warnings after the update was,
    Passing a class to the 'class_name' is deprecated and will raise an ArgumentError in Rails 5.2.
    It eagerloads more classes than necessary and potentially creates circular dependencies. Please pass the class name as a string:
    

    This warning message was due to passing a class to `class_name` option when specifying associations – this is no longer recommended

    - has_one :contact, class_name: UserContact
    + has_one :contact, class_name: 'UserContact
    
    passing class name as a string is a standard now Happy Hacking ❤  
    PS: If you need any help in upgrading your rails version drop an email to us at [email protected] or [email protected] We will be more than happy to go through your system and give a free upgrade action plan and estimation .]]>