简体   繁体   English

Rails Mailer:尝试使用 URL 帮助程序时“没有路由匹配 {}”

[英]Rails Mailer: “No route matches {}” when trying to use URL helpers

I can't get the *_url helpers to work in my mailers.我无法让*_url助手在我的邮件程序中工作。

For example, I have resources :pages in my routes.rb .例如,我的routes.rbresources :pages

But when trying to use any of the helpers in a mailer view, it's always telling me:但是当尝试在邮件程序视图中使用任何帮助程序时,它总是告诉我:

ActionController::UrlGenerationError
No route matches {}

The following tests may give some more hints...以下测试可能会给出更多提示......

root_url                # results in No route matches {}
pages_url               # results in No route matches {}
page_url                # results in No route matches {:action=>"show", :controller=>"pages"}, missing required keys: [:id]
page_url 1              # results in No route matches {:action=>"show", :controller=>"pages", :locale=>1}, missing required keys: [:id]
page_url 1, locale: :en # results in No route matches {}

I have no idea how to debug and fix this any further.我不知道如何进一步调试和解决这个问题。

This likely happened because link_to requires two parameters.这可能是因为link_to需要两个参数。 I came across this issue when using link_to in a text-based mailer, so here's how I solved it:我在基于文本的邮件程序中使用link_to时遇到了这个问题,所以我是这样解决的:

Instead of this:取而代之的是:

Click here to verify this user: <%= link_to @user %>

Try this:试试这个:

Click here to verify this user: <%= users_url(@user) %>

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

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