在我的 application.html.erb 我有<%= render @objects %>
,它呈现了一堆_object.html.erb
部分,每个部分都有一个<%= link_to(object) %>
. 当有人发表评论时,我在发送的电子邮件中呈现相同的单个部分<%= render @object %>
,但我希望链接以服务器 url 开头。
我已经尝试了一切:
link_to(object)
url_for(object)
before_filter :set_mailer_host
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
end
default_url_options[:host] = "example.com"
def default_url_options
{ host: 'example.com' }
end
...没有任何作用。有还是没有:only_links
最后,我只是构建了一个愚蠢的助手,将主机名添加到链接:
# application_controller.rb
before_filter { App::request=request }
# application_helper.rb
def hostify obj
"http://#{App::request.host_with_port}#{url_for obj}"
end
# _object.html.erb:
<%= link_to obj.title, hostify(object) %>
有没有正常的方法可以做到这一点?