How do I configure the hostname for Rails ActionMa

2019-02-03 06:12发布

I'm working on a fairly traditional forgot password email - I want to email the user a password change token embedded in a link that they can click on in order to change their password. I'm emailing via the traditional ActionMailer.

If I use a normal link_to tag

<%= link_to "click here", :controller => foo, :action => 'bar', :token => token %>

I get a relative link - rather useless from an email.

If I add in

:only_path => false, then it errors saying I need to set default_url_options[:host]. The ActionController docs imply that you do that by overriding the #default_url_options methods in your controller. Surely there's a configuration option to tell Rails what it's hostname is without adding my own config file, parsing it, etc?

7条回答
神经病院院长
2楼-- · 2019-02-03 06:55

You probably want to set :protocol => 'https' as well, btw.

config.action_mailer.default_url_options = { 
    :host => "portal.example.com", 
    :protocol => 'https' 
}
查看更多
登录 后发表回答