I have a web app: front-end in Angular and back-end in Rails.
I have a custom domain www.example.com
and redirects users to heroku URL(example.herokuapp.com
).
After user signs up, they need to confirm their emails. When they receive an email from my web app, they click the link. I use Devise to confirm user's email by the way.
It is supposed to take the user to www.example.com/log_in
. However, for some reason, the user is taken to example.herokuapp.com/log_in
. How do I redirect the user to custom domain for this edge case?
To do this you want to override the default_url_options
in your environment config files. For example, in your config/environments/production.rb
you'll probably want the following:
config.action_mailer.default_url_options = {
host: 'http://www.example.com'
}
config.action_mailer.asset_host = 'http://www.example.com'
Whatever you set the host
of default_url_options
to will be the host of any links contained inside emails sent out through ActionMailer (this includes Devise confirmation / password-reset emails). asset_host
is used as the host for any assets (eg images) you put inside of your emails, so that they can be found correctly.
Just in case someone else was an idiot like me, I spent hours trying to figure out why my user confirmation link worked on development but not on production. The confirmation link would just redirect me to my landing page with no errors.
I have my domain hosted on Google domains with the naked domain forwarding to 'www'. In my config/environments/production.rb file I had set the host to my naked domain:
host: 'example.com'
The problem was in my google domain settings. It was redirecting the domain but NOT forwarding the path, hence the redirecting right to my landing page. Make sure you are also forwarding the path or include the www in your host setting:
host: 'www.example.com'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With