0

When the user requests a reset-link sent to his email using Devise views, he receives an email with this content:

Hello example@gmail.com!

Someone has requested a link to change your password. You can do this through the link below.

Change my password
(which points to)
localhost:3000/users/password/edit?reset_password_token=some_token

If you didn't request this, please ignore this email.
Your password won't change until you access the link above and create a new one.

Now, this is all cool and dandy, except when I host the rails server on a different port, say

rails server -p 5678

Then the link still points to localhost:3000.

I know about request.ip and request.port, but I cannot find out where to change the Devise mailer objects. The relevant part of the mail-template used for this mail is

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

After debugging, it seems @resource is a User-object and this contains no URL.

Long story short: How can I make the url (ip/port part) of Devise mails be dynamic?

krystah
  • 3,587
  • 2
  • 25
  • 43
  • There are various ways to use the current host and ip in mailer urls. One among them is explained nicely in [this article](http://makandracards.com/makandra/1353-make-actionmailer-use-the-current-request-host-and-protocol-for-url-generation). Just follow this. – Sagar Bommidi Jun 04 '14 at 14:53
  • Does this answer your question? [How to set the ActionMailer default\_url\_options's :host dynamically to the request's hostname?](https://stackoverflow.com/questions/3432712/how-to-set-the-actionmailer-default-url-optionss-host-dynamically-to-the-reque) – sureshprasanna70 Nov 06 '19 at 06:24

0 Answers0