Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inherited app with strange routing error, No route matches {}

Whenever one of the mailers fires off if the body contains something like link_to root_url it gives this incredibly unhelpful error:

ActionView::Template::Error: No route matches {}

The trace either is useless or points to that link_to method. Since it's also very unsearchable here I am asking on stack overflow.

UPDATE 1: To help, I've posted the terrifying routes.rb file: https://gist.github.com/2955610

UPDATE 2: In the console, app.root_url provides the correct return.

UPDATE 3: link_to "whatever", root_url works just fine. So strange!

UPDATE 4: It works fine in a regular rails view.

UPDATE 5: FIXED The image_tag now isn't providing a host in the email, outputting: http://assets/...png. Fffff.

UPDATE 6: I've narrowed it down to that I get the same error with (in console) app.url_for. I think it may be related.

like image 904
krainboltgreene Avatar asked Jun 19 '12 17:06

krainboltgreene


1 Answers

So the real answer is that link_to works differently in ActionMailer than in ActionController. The difference is that apparently ActionController has an option called :script_name, and this makes all sorts of assumptions for you.

Now while I don't agree with that difference there's not much you can do about it, so here's what I ended up doing:

link_to root_url, root_url

Now, why would I use both? Well two reasons:

  1. I wanted the url as the anchor text and the href.
  2. If the URL changes, I don't want to have to update all those strings.
like image 141
krainboltgreene Avatar answered Nov 14 '22 21:11

krainboltgreene