我能够在整个网站中使用变量,但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
答案 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}")