Question

Using Devise 3 and Rails 4, I would like to add an image to my confirmation email.

I tried...

Views/Devise/Mailer/confirmation_instructions.html.erb

<%= image_tag("my_image.png") %>

...the image however is showing up as a default placeholder question mark.

How should I correctly access the asset?

Was it helpful?

Solution 2

Replace

<%= image_tag("my_image.png") %>

With

<%= image_tag "http://mydomain.com/path/to/my_image.png" %>

For example:

<%= image_tag "https://www.google.com/images/srpr/logo11w.png" %>

The above example would add Google Logo in your email body.

If you want your own image to be shown then replace

mydomain.com : Your domain name

/path/to : Path to your folder where my_image.png resides

OTHER TIPS

There is another way to supply an image in a Devise confirmation email - attach it to the letter.

See the instructions:

1. Create your own mailer:

app/mailers/my_devise_mailer.rb

class MyDeviseMailer < Devise::Mailer

  helper :application # gives access to all helpers defined within `application_helper`.
  include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
  default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views

  def confirmation_instructions(record, token, opts={})
    attachments.inline['logo.jpg'] = File.read("app/assets/images/logo.jpg")
    super
  end

end

2. In your config/initializers/devise.rb, set config.mailer="MyDeviseMailer".

3. In your app/views/devise/mailer/confirmation_instructions.html.erb use

<p><%= image_tag(attachments['logo.jpg'].url, width: '120', height: '120') %></p>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top