0

context

when I try to do an inline image attachment with actionmailer it throws the following error

undefined method `url' for nil:NilClass

code

in mailer

  def inline_image(image_name)
    attachments.inline[image_name] = File.read())
  end

  def shared_user_email()
    inline_image(image_name_string)
    mail(to: email, subject: whatever)
  end

in template

  <%= image_tag attachments[image_name].url %>

in controller

UserMailer.delay.shared_user_email()

tried

Tried using a specific hash (Rails attachments inline are not shown correctly in gmail)

Tried setting the content_Id (Rails mailer error with inline attachment)

No dice.

Community
  • 1
  • 1
Morgan
  • 1,438
  • 3
  • 17
  • 32
  • You need to specify the absolute path of the file you're trying to read as a parameter in File.read(). – rb512 Aug 30 '14 at 00:19
  • 1
    This uses the DelayedJob gem? Not all things that work eagerly will continue to work after queuing as a delayed job. Does `UserMail.shared_user_email()` work from a rails console without the delay? @rb512 's comment is very likely correct. The `File.read()` returns `nil` after queuing. – Gene Aug 30 '14 at 01:20
  • If I take out delayedJob is works; thanks! – Morgan Aug 31 '14 at 01:15
  • Gene if you put up the issue with delayed jobs as the solution I'll accept it. Your call. – Morgan Sep 08 '14 at 23:03

0 Answers0