简体   繁体   English

ActionMailer视图中的绝对URL

[英]Absolute url in ActionMailer view

I have an asynchronous job that sends an email to the user when it completes. 我有一个异步作业,在完成后向用户发送电子邮件。 I'm testing the send email function with rspec. 我正在使用rspec测试发送电子邮件功能。

In environments/test.rb I have this line 在environment / test.rb中我有这一行

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

In the action mailer view I have this line, 在动作邮件视图中我有这条线,

= link_to(@submission.title, @submission, {:only_path => false})

This generates a relative url 这会生成一个相对URL

<a href="/submissions/1" only_path="false">Test Submission 1</a>

What I need is 我需要的是

<a href="http://localhost:3000/submissions/1">Test Submission 1</a>

Call the named route directly instead of allowing Rails to generate it for you. 直接调用命名路由,而不是允许Rails为您生成它。 So turn your link into this: 所以把你的链接变成这样:

= link_to(@submission.title, submission_url(@submission))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM