2

我想創建一個郵件給用戶,其中包括一個簡單的HTML表單。爲此,我使用Rails 3中的ActionMailer,如教程中所建議的http://edgeguides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration如何在導軌3的郵件程序中使用表單助手?

我無法在郵件erb文件中使用ActionView助手,如form_tag。我如何在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> 
+1

無法工作的唯一幫手是form_tag,因爲它需要protect_from_forgery?它僅由ActionController實現,並且在ActionMailer的視圖中不可用。所以我可以通過手動生成form_tag helper的html來解決它。其餘的助手(check_box_tag,submit_tag)工作正常。 – 2011-06-15 06:12:06

回答

0

這不是一個好主意,把你的形式在電子郵件中看到:

http://www.campaignmonitor.com/blog/post/2435/how-forms-perform-in-html-emai/

但是你在這裏看到的是表單正在發送沒有csrf_meta_tag(表單令牌和身份驗證)。您可以爲此操作關閉僞造保護功能,也可以手動將這些字段添加到您的表單中。

+0

感謝您的鏈接。由於方法protect_from_forgery,即使關閉頂層的僞造保護也無濟於事。是form_tag所必需的。 – 2011-06-15 06:14:08

+0

表單很小,你可以手動編寫html代碼嗎? – MatthewFord 2011-06-16 17:45:18