Question

I am testing on my localhost. Here is the action_mailer section of my development.rb file:

config.action_mailer.delivery_method = :smtp

config.action_mailer.smtp_settings = {
    :address   => "smtp.mandrillapp.com",
    :port      => 587,
    :user_name => "my_email@email.com,
    :password  => ENV['MANDRILL_API_KEY'],

}

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

and here is the action_mailer file:

def confirm_email(user, school, email)
   @user = user
   @school = school
   @email = email
   @url  = 'http://example.com/login'
  mail(to: @email, subject: 'Please confirm your additional school email.')
end

and here is the view:

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1>Hello <%= @user.first_name %></h1>

    <p>
      To confirm your additional school, <%= link_to "click here", verify_other_school_path(@school) %>.
    </p>
    <p>Thanks and have a great day!</p>
  </body>
</html>

The email is working and sending properly. The only problem is that the html generated for the link looks like:

<a href="http://verifyotherschool/4" target="_blank">click here</a>

instead of the way it should:

<a href="http://localhost:3000/verifyotherschool/4" target="_blank">click here</a>

How do I fix this?

Was it helpful?

Solution

remember path is relative while url is absolute.
instead

  verify_other_school_path(@school)

use

  verify_other_school_url(@school)

or

  verify_other_school_path(only_path: false, @school)

and read this

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top