rails/rails — pull request #16589 by schneems (2014-08-20 18:36:29+00:00)
Title: Default url_to to a full URL in mailer when possible

[close #16497]

Currently `link_to ..., @user` will generate a non working link inside of a mailer. This is because it delegates to url_for https://github.com/rails/rails/blob/master/actionview/lib/action_view/routing_url_for.rb#L95 which produces a path by default instead of a url. This PR defaults all output of `url_for` to be a full url (instead of a path) when possible.

It is important to note that there is a `url_for` inside of the mailer view (as referenced above) and there is also a `url_for` that can be called inside of a mailer method:

```
class UrlTestMailer < ActionMailer::Base

def exercise_url_for(options)
@from_method = url_for(options)
mail(to: "foo@foo.com", subject: "Welcome",
from: "system@loudthinking.com", date: Time.local(2004, 12, 12))
end
end
```

This second `url_for`, called from a mailer method directly delegates to a __different__ `url_for` located in https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/url_for.rb. This second `url_for` produces a URL by default.

This PR merges both behaviors by having the view `url_for` invoke the `url_for` defined on the mailer (the "controller" in this case). This should prevent #16497 and provide seamless mailer experience