Add the following to the Application class in config/application.rb:

default_url_options[:trailing_slash] = true

For example, the application MyApplicationName will look something like this:

module MyApplicationName
  class Application < Rails::Application
    default_url_options[:trailing_slash] = true
  end
end

The Rails server will need restarting for the new settings to take effect.

This solution works for Rails 5 and will add a trailing slash to all urls automatically.