我正在处理rails应用程序,并希望将带有内嵌图像的电子邮件发送到用户输入的电子邮件地址。我一直在努力做到这一点。我在网上查了一下这就是我做的。
当我在开发中输入电子邮件时,它给出了一个错误说, 的ActionController :: UnknownFormat
这是我的ActionMailer Notifier.rb
class Notifier < ActionMailer::Base
default from: "insidespintex@gmail.com"
def enter_email(sending)
@coming = sending
attachments.inline['blank'] = {
:data => File.read("#{Rails.root.to_s + '/app/assets/images/News.png'}"),
:mime_type => "image/png",
:encoding => "base64"
}
mail :to => @coming.email, :subject => 'InsideSpintex is coming soon'
end
end
这是我的ApplicationController LandingController.rb
class LandingController < ApplicationController
layout 'landingPage'
def soon
@coming = Coming.new
end
def after
render 'after'
end
def save_email
@coming = Coming.new(soon_params)
respond_to do |format|
if @coming.save
Notifier.enter_email(@coming).deliver
format.html { render action: 'after' }
#render 'after'
else
render 'soon'
end
end
end
#render 'soon'
private
def soon_params
params.require(:coming).permit(:email)
end
end
这是我的查看enter_email.html.erb
<p> Hello There,</h3>
<%= image_tag attachments['News.png'] %>
答案 0 :(得分:3)
好吧,我认为你的attachments.inline哈希中不需要编码部分。我在一个项目中使用了这样的东西:
梅勒方法:
attachments.inline['logo.png'] = {
data: File.read(Rails.root.join('app/assets/images/logo.png')),
mime_type: 'image/png'
}
并且您错过了视图中的.url
:
<%= image_tag attachments['logo.png'].url %>