How do I configure the hostname for Rails ActionMailer?

前端 未结 7 1246
日久生厌
日久生厌 2020-12-29 06:05

I\'m working on a fairly traditional forgot password email - I want to email the user a password change token embedded in a link that they can click on in order to change th

相关标签:
7条回答
  • 2020-12-29 06:47

    default_url_options is available from config.action_mailer and should be set in your environment's configuration file.

    For example, in config/environments/production.rb:

    config.action_mailer.default_url_options = {
      :host => 'www.yourdomain.com'
    }
    

    For local testing, modify config/environments/development.rb:

    config.action_mailer.default_url_options = {
      :host => '127.0.0.1',
      :port => 3000
    }
    

    Then, assuming you have a named route called forgot_password_login, you can generate the login link URL in your mailer using something like this:

    forgot_password_login_url(:token => 'a7s8q15sk2...')
    
    0 讨论(0)
提交回复
热议问题