How to set config.action_controller.default_url_options = {:host = '#''} on per environment basis

心不动则不痛 提交于 2019-11-28 17:09:44
trying_hal9000

Okay I figured it out the correct way to write it is

Rails.application.routes.default_url_options[:host] = 'localhost:3000'

:)

You have to restart your server before the changes to this file takes effect.

Inherit your Application's default_url_options from ActionMailer.

You want to keep things as DRY as possible so, ideally, you don't want to hard code your host and port in multiple places for the same environment, unless your ActionMailer actually uses a different host and port than the rest of your Application.

To set the default_url_options for your entire Application, simply add the following line to your config/environment.rb file (changing MyApp to your app's name):

# Set the default host and port to be the same as Action Mailer.
MyApp::Application.default_url_options = MyApp::Application.config.action_mailer.default_url_options

This will fix your problem and automatically set your Application's default_url_options to the same as your config.action_mailer.default_url_options:

$ MyApp::Application.config.action_mailer.default_url_options
#=> {:host=>"lvh.me", :port=>"3000"}

$ MyApp::Application.default_url_options
#=> {:host=>"lvh.me", :port=>"3000"}

config.action_mailer.default_url_options = { :host => "your host" }

for instance your host localhost:3000

you can put this in test.rb, development.rb, production.rb files host could be different from environment to environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!