我正在使用 Ruby on Rails 3.1.0,我想在 HTML 电子邮件中正确生成 URL。在我设置的环境文件中
config.action_mailer.default_url_options = { :host => 'my_site.org' }
在电子邮件视图文件 ( .html.erb
) 中,我声明
<%= link_to @user.name, users_url(@user) %>
当我去查看收到的电子邮件时,生成的 URL 是http://users/1
,当然不正确。那么,如何在邮件模板中生成正确的 URL,以便http://my_site.org/users/1
在正文中包含链接?
我也尝试default_url_options
在我的mailer.rb
文件中设置
class MyCustom::Mailer < ActionMailer::Base
default_url_options[:host] = 'my_site.org'
def test_sending
...
end
end
但它不起作用。