2

I'm current using Ruby on Rails 3.2.8 and am trying to send an email using ActionMailer with an image inside of body of the email. I've searched online and none of the instructions help. Here is an example of something I used from a Railscasts episode:

user_mailer.rb

def registration_confirmation(user)
  @user = user
  attachments["rails.png"] = File.read("#{Rails.root}/public/images/corporate_logo.png")
  mail(:to => "#{user.name} <#{user.email}>", :subject => "Registered")
end

registration_confirmation.html.erb

<%= image_tag("corporate_logo.png", :alt => "CorporateLogo") %>
<p><%= @user.name %>,</p>
<p>Thank you for registering!</p>
<p><%= link_to "Edit profile", edit_user_url(@user) %></p>

Thanks!

perseverance
  • 6,372
  • 12
  • 49
  • 68

1 Answers1

2

Try to follow the example here. I haven't tried it but it should work. Its formatted for the recent rails, the example in that railscasts episode is for versions of rails before they added the asset pipeline.

try:

attachments['rails.png'] = File.read('/assets/corporate_logo.png')

or

attachments['rails.png'] = File.read('corporate_logo.png')

Or perhaps refer to this answer, may help you. They have it set up like this:

attachments["rails.png"] = File.read("#{Rails.root}/app/assets/images/corporate_logo.png")
Community
  • 1
  • 1
Dol
  • 944
  • 3
  • 10
  • 25