Just updated a Rails 3.2 application to Rails 4.2 and started getting a funny error. Anytime I try to call link_to
with a single argument inside my mailer template, I get an error. However, I can make the same call just fine within one of my regular views.
Inside of my mailer view, I try to call it like this:
# user_mailer/notify.html.haml
...
= link_to "https://example.com"
But when the email gets processed by my job handler, it reports the error ActionView::Template::Error: No route matches {:action=>"index"}
. (Interestingly enough, this is what you get when you try to call url_for
without any parameters).
However, on my homepage I have no issue using the same thing:
# home/index.html.haml
...
= link_to "https://example.com"
Outputs:
<a href="https://example.com">https://example.com</a>
As far as I can tell looking at the docs, nothing changed with link_to
between Rails 3.2 and 4.2 so I'm confused why this would stop working... Also confused why it works in one place, but not the other.
link_to
with just one parameter doesn't do what you think it does. If you look at the generated link in your view it just points to the site you're currently on. You have to provide two parameters, the body and the url.
= link_to "https://example.com"
# <a href="/">https://example.com</a>
You will need this however
= link_to "https://example.com", "https://example.com"