4

The Error I get:

ActionView::Template::Error (undefined method `url' for nil:NilClass)

I have this attachment that is comming up nil

<%= image_tag attachments['tippedlogods.png'].url %>

That being said, I have declared the attachment in the method to send the email, here:

  def confirmation(order)
    @order = order
    mail(to: @order.email, subject: "Order Confirmation", content_type: "text/html")
    attachments.inline['tippedlogods.png'] = File.read("app/assets/images/tippedlogods.png")
  end

In my production.rb:

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { :host => 'hidden-peak-xxxx.heroku.com', :only_path => false}
  config.action_mailer.asset_host = 'hidden-peak-xxxx.heroku.com'
  ActionMailer::Base.smtp_settings = {
  :address    => "smtp.sendgrid.net",
  :port       => 587,
  :user_name  => ENV['SENDGRID_USERNAME'],
  :password   => ENV['SENDGRID_PASSWORD'],
  :domain     => ENV['SENDGRID_DOMAIN'],
  :authentication  => :plain
  }

Is this not the way to go about sending an image in a confirmation email?

I was following RoR Guides here...

Note Rails 4~

1

1 Answer 1

7

You are calling mail first before you add the attachment. So there is no attachment when it renders the template!

http://apidock.com/rails/ActionMailer/Base/mail

Change the order of statements.

attachments.inline['tippedlogods.png'] = File.read("app/assets/images/tippedlogods.png")
mail(to: @order.email, subject: "Order Confirmation", content_type: "text/html")
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.