user1322092
user1322092

Reputation: 4270

Rails - using `url_for` with route path in email does not include host

While not documented well nor shown in examples, url_for can be used with paths (e.g., url_for(signup_path) would produce /signup) vs controllers and actions.

However, in doing do it does not include the host if one set in corresponding environment file.

reference: http://api.rubyonrails.org/classes/ActionDispatch/Routing/UrlFor.html

Why is this the behavior?

Upvotes: 0

Views: 685

Answers (2)

Brady
Brady

Reputation: 21

Using url_for to generate a link in an email is probably not the way you want to go. In any case use signup_url not signup_path if you want the proper environment appended to the link.

<%= link_to "Signup", signup_url %>

Upvotes: 0

Substantial
Substantial

Reputation: 6682

If you want the full URL, use:

url_for(signup_url)

From the Rails Guide on route helpers:

Each of these [_path] helpers has a corresponding _url helper (such as photos_url) which returns the same path prefixed with the current host, port and path prefix.

Upvotes: 2

Related Questions