jpf*_*es2 3 actionmailer actionview form-helpers ruby-on-rails-3
我在模板new.html.erb中有一个form_for,我正常保存到数据库,然后成功发送电子邮件.我希望邮件程序发送相同的new.html.erb作为正文并传递模型,以便完全填充表单.我收到以下错误:
undefined method `protect_against_forgery?' for #<#<Class:0x000000049d7110>:0x000000049d4690>
Run Code Online (Sandbox Code Playgroud)
在form_for标记之后的行上(因为它注入了我认为的auth令牌标记).有没有办法可以规避这一点,以便我可以在邮件中重复使用该模板?
这是邮件代码的样子
class MaintenanceMailer < ActionMailer::Base
helper :application
def request_email(maintenance)
mail :to => maintenance.community.email, :subject => "Maintenance" do |format|
format.html { render :layout => 'default', :template => 'maintenance/new' }
end
end
end
Run Code Online (Sandbox Code Playgroud)
将此添加到只有您的邮件程序模板使用的帮助程序:
def protect_against_forgery?
false
end
Run Code Online (Sandbox Code Playgroud)
但是请确保接收控制器跳过verify_authenticity_token,并且该会话顶层对于该表单所携带的内容是可以的.