RamJet
RamJet

Reputation: 313

Ruby on Rails -- a link doesn't work in an email generated by ActionMailer

I've read the "Action Mailer Basics Guide". Here is my code:

def send_email
  @url = 'my url'
  mail(to: 'my email address', subject: 'my subject')
end

Here is my template:

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
  </head>
  <body>
    <p>
      Hi. This is your notification.
    </p>
    <p>
      Please click this link: <%= @url %>
    </p>
  </body>
</html>

That is the same as in the guide. The problem is that <%= @url %> is not formatted as a link when the email is received. The link by itself is fine.

Does anyone know what's wrong?

Upvotes: 0

Views: 321

Answers (1)

Danil Speransky
Danil Speransky

Reputation: 30473

Thta's because you didn't wrap it with <a>, so it's displayed as plain text. Try this:

<%= link_to "Link", @url %>

It would generate HTML:

<a href="my url">Link</a>

Upvotes: 1

Related Questions