Skip to content

Upgrading from v3.x to v4.x

Brian Riley edited this page Oct 24, 2022 · 1 revision

Upgrading from v3.x (Rails 5 and Ruby 2.6) to v4.x (Rails 6 and Ruby 2.7)

DMPRoadmap v4.x is a major upgrade that brings the system up to Rails 6.1 and Ruby 2.7. Please review the following information as it may impact your local customizations.

New configuration:

The following is a list of configuration changes you will need to make to your local installations to support Rails 6+:

  • New environment variable called DMPROADMAP_HOST. Rails 6+ introduces new middleware that helps mitigate DNS rebinding attacks. This includes a hostname whitelist. The whitelist includes localhost for the development environment, but does not include anything in other environments. Set export DMPROADMAP_HOST=my.example.org appropriately for each environment. If you have other hostnames you need to support, you can adjust the config/application.rb file to include them.
  • We needed to reconfigure the config/translation.rb so that it does not reference Rails framework elements that have not yet been defined. Please review this file and adjust the SUPPORTED_LOCALES, CLIENT_LOCALES and DEFAULT_LOCALE constants at the top as needed.

Potential issues for your customizations:

The following issues have been addressed as part of the Ruby and Rails upgrades. You should inspect your instances customizations to determine if you will need to make similar adjustments.

  • The ActiveModel update_attributes method has been deprecated. Use update instead.
  • serialize must be called after the attribute definition in ActiveModel. For example serialize :my_attr, JSON; attribute :my_attr, :text, default: 'foo' will return a text string instead of parsed JSON. To correct this, just flip the order so that serialize is called last
  • You should use the record.errors.add(attribute, message) method for ActiveRecord errors instead of record.errors[attribute] << message format
  • Introduction of Zeitwerk which is used to handle Rails' convention over configuration tooling. It is stricter than the classic version so your naming conventions must adhere to Rails standards:
    • Camel case module and class names only. For example JsonLinkValidator instead of JSONLinkValidator
    • file names and directory structures must match module/class definitions. For example app/controllers/contacts_controller.rb with module ContactUs; class ContactsController < ApplicationController is invalid. The directory structure should be app/controllers/contact_us/contacts_controller.rb. You can run rails zeitwerk:check to help find any issues.
  • Attempting to access Rails objects that are typically only available after the application has initialized within an initializer is invalid. For example, we can no longer reference DB tables like Language.all in the config/translation.rb because Zeitwerk will attempt to auto-load objects that have not yet been defined.