试图在rails上实现一个angularjs红宝石.
当我试图将一个真实性令牌嵌入到我的angularjs表单中时,我会遇到这样的错误:
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>我知道这个错误
undefined local variable or method `form_authenticity_token' for #<#<Class:0x00000005953418>:0x007fcdc1205b20>我真的很想能够在我的angularjs表格中包含真实性标记。
发布于 2015-10-14 02:39:15
令牌只能在控制器中访问,而不能在视图中访问。您得到了所提到的错误,因为您正在尝试在您的视图中使用该错误。
您可以在相应控制器的操作中定义一个实例变量,如下所示:
# in controller
def your_action
@form_auth_token = form_authenticity_token
end然后,在视图中使用@form_auth_token:
<%= hidden_field_tag :authenticity_token, @form_auth_token %>https://stackoverflow.com/questions/33115664
复制相似问题