【发布时间】:2011-09-13 19:37:19
【问题描述】:
我正在尝试为用户创建一封邮件,其中包含一个简单的 html 表单。为此,我正在使用 Rails 3 中的 ActionMailer,如 http://edgeguides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration 教程中所建议的那样
我无法在邮件程序 erb 文件中使用诸如 form_tag 之类的 ActionView 帮助程序。如何在 erb 文件中访问它们。
我的 user.html.erb 文件有这样的代码:
<%= form_tag(:controller => "application", :action => "parent_select", :method=>"put") do %>
Want To Attend
<%= check_box_tag(:yes, '1', request.priority != 0) %>
<% end %>
我收到此错误:
undefined method `protect_against_forgery?' for #<#<Class:0xa0874c4>:0xa085a70>
【问题讨论】:
-
唯一不起作用的助手是form_tag,因为它需要protect_from_forgery?它仅由 ActionController 实现,在 ActionMailer 的视图中不可用。所以我可以通过为 form_tag 助手手动生成 html 来解决它。其余的助手(check_box_tag、submit_tag)工作正常。
标签: ruby-on-rails ruby-on-rails-3 actionmailer actionviewhelper