【问题标题】:Rails Mailer: "No route matches {}" when trying to use URL helpersRails Mailer:尝试使用 URL 帮助程序时“没有路由匹配 {}”
【发布时间】:2018-06-28 18:42:16
【问题描述】:

我无法让 *_url 助手在我的邮件程序中工作。

例如,我的routes.rb 中有resources :pages

但是当尝试在邮件视图中使用任何帮助程序时,它总是告诉我:

ActionController::UrlGenerationError
No route matches {}

以下测试可能会提供更多提示...

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 {}

我不知道如何进一步调试和修复这个问题。

【问题讨论】:

  • 您是如何使用这些网址的? link_to?
  • 你说得对,我认为这只是我的一个愚蠢的错误。它现在像这样工作:link_to 'page 1', page_url(1, locale: :de)!
  • 好的:)。 link_to 需要两个参数我猜你只传了一个
  • 是的,这就是问题所在。我在同一个视图中使用了mail_to 助手,而mail_to 只需要一个参数(它只是将它用于链接文本和目标),link_to 总是需要两个参数。

标签: ruby-on-rails url routes actionmailer


【解决方案1】:

这可能是因为link_to 需要两个参数。我在基于文本的邮件中使用link_to 时遇到了这个问题,所以我是这样解决的:

而不是这个:

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

试试这个:

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

【讨论】:

  • 这不还是一个带资源url的参数吗?
猜你喜欢
  • 2011-11-14
  • 1970-01-01
  • 1970-01-01
  • 2022-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多