{@ ticket.image_file_name}在ActionMailer附件中不起作用,但在其他地方都很好

时间:2014-07-10 23:07:23

标签: ruby-on-rails actionmailer

我能够在整个网站中使用变量,但ActionMailer的附件部分除外。您对我收到以下错误的原因有任何建议:

Errno::ENOENT: No such file or directory - https://s3.amazonaws.com/logos/#{@ticket.image_file_name}

这是ActionMailer代码:

def generate_tickets(ticket,business,contact,user)
  @business = business
  @ticket = ticket
  @contact = contact
  @user = user
  mail(from: "#{@ticket.user.first_name} #{@ticket.user.last_name} <reply@callred.com>", :to => "<#{@ticket.contact.email}>", subject: "Message is on its way")
  attachments['#{@ticket.image_file_name}'] = File.read('https://s3.amazonaws.com/logos/#{@ticket.image_file_name}')
  headers['X-MC-GoogleAnalytics'] = ENV["DOMAIN"]
  headers['X-MC-Tags'] = "New Ticket"
  headers['X-MC-Template'] = "maintheme|email_message"
end

1 个答案:

答案 0 :(得分:1)

使用字符串插值时,需要使用双引号而不是单引号。

变化:

attachments['#{@ticket.image_file_name}'] = File.read('https://s3.amazonaws.com/logos/#{@ticket.image_file_name}')

致:

attachments["#{@ticket.image_file_name}"] = File.read("https://s3.amazonaws.com/logos/#{@ticket.image_file_name}")