在我的Ruby on Rails应用程序中,我试图在电子邮件中嵌入徽标以便内联显示,但由于某种原因它没有出现(请参见下图)。我试图按照Stack Overflow问题What is the right way to embed image into email using Rails?上的答案进行操作,但无法使其工作。
我的邮件如下:
class UserEmails < ApplicationMailer
def send_email(email, unsubscribe)
@url = 'http://localhost:3000/users/login'
@email = email
@unsubscribe = unsubscribe
attachments.inline['logo.jpg'] = File.read('app/assets/images/logo.jpg')
mail(from: "#{@email.from_name} <#{@email.account.email}>", to: @email.to, cc: @email.cc, bcc: @email.bcc, subject: @email.subject)
end
end
我的电子邮件视图:
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1><%= @email.subject %></h1>
<p>
<p>
To
<%= image_tag attachments['logo.jpg'].url %>
<%= link_to "Unsubscribe", settings_unsubscribe_url(id: @unsubscribe) %>
</body>
</html>
有人能告诉我为什么这不起作用吗?