2022-04-01

Setting default url options

If you are managing an application that has a staging version, you will need to point default_url_options[:host] to the correct host domain. If not, features that depend on host domains(i.e. uploading to cloudinary or sending out an email from your application)will not work.

# application_controller.rb
def set_default_url_option
  if ENV["HOST"]
    {host: ENV["HOST"]}
  elsif Rails.env.production?
    {host: 'https://app-name.com'}
  else
    {:host => "localhost", :port => "3000"}
  end
end

Set env variable in your staging app

heroku config:set --app app_name_staging HOST="https://staging.app-name.com"