在Mailer视图中生成完整的URL - Rails

时间:2014-07-19 15:02:59

标签: ruby-on-rails ruby-on-rails-4 routing actionmailer url-for

邮件视图中的

      <%= url_for(controller:'resas', action: 'show', only_path: false) %>

rake routes:

                      resa GET    /resas/:id(.:format)             resas#show

尝试生成电子邮件时出现以下异常:

No route matches {:action=>"show", :controller=>"resas"}

我的主机已参数化(作为localhost)。

2 个答案:

答案 0 :(得分:2)

我认为你需要为show路径传入一个id。试试

<%= url_for(controller:'resas', action: 'show', id: @resa.id, only_path: false) %>

(不确定您的资源是如何命名的)

答案 1 :(得分:0)

至少您的路线语法不正确。尝试:

#routes.rb
GET    /resas/:id(.:format), to: resas#show

在此处的rails文档中阅读有关路由和路由语法的所有内容:http://guides.rubyonrails.org/routing.html

看起来您可能想要在不提供主机名的情况下重新考虑only_path: false。在此处阅读有关url_for和only_path的更多信息:http://api.rubyonrails.org/classes/ActionDispatch/Routing/UrlFor.html