Joshua Muheim
Joshua Muheim

Reputation: 13195

Rails Mailer: "No route matches {}" when trying to use URL helpers

I can't get the *_url helpers to work in my mailers.

For example, I have resources :pages in my routes.rb.

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.

Upvotes: 1

Views: 984

Answers (1)

Tim B.
Tim B.

Reputation: 467

This likely happened because link_to requires two parameters. I came across this issue when using link_to in a text-based mailer, so here's how I solved it:

Instead of this:

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

Try this:

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

Upvotes: 3

Related Questions