user5468794 user5468794 - 1 year ago 72
HTML Question

How to href my ruby code in an html

I currently have the code below in my html which gets sent as an email. I would like for it to say here as a hyperlink. I have seen and know how to do

but I do not think that would work in html format or if it does I am not sure how to do it properly.

This code directs the user to a link in my web app with a parameter.


Any help or insight would be appreciated.

Answer Source

Ok so assuming you have an ActionMailer called MyMailer, with a single method send_link. Just as you would for a controller action, set any instance variables within the send_link method to be used by the email view for rendering.


class MyMailer < ActionMailer::Base
  default from: ''

  def send_link(user, host)
    @user = user
    @host = host

    mail(to:, subject: "Here is your link")

Next create a view for this just as you would for a controller actions views and write your html with any necessary erb.


<p>Dear <%= @user.forename %>,</p>

<p>Here is your link</p>

<p><%= link_to 'Click Me', landlord_page_url(@user, host: @host) %></p>

And you are done.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download