我已经知道了如何在控制器中禁用authenticity_token,但是rails仍然会在表单中创建该字段。当我向其发送表单的服务器需要一组非常具体的字段名称时,我该如何关闭它呢?
发布于 2012-07-15 06:03:08
在3.2.x之后的rails中,您可以按照另一个答案中的建议将参数传递到表单生成器中:
form_for @invoice, :url => external_url, :authenticity_token => false do |f|
...
<% end %>在任何rails版本中,您都可以在config/application.rb中全局禁用,如另一个答案所示:
config.action_controller.allow_forgery_protection = false在rails 3.0.x中,您可以通过覆盖以下方法在控制器中禁用页面加载。不幸的是,似乎没有办法在表单级别做到这一点。
protected
def protect_against_forgery?
if ...
# results in the meta tag being ommitted and no forms having authenticity token
return false
else
# default implementation based on global config
return allow_forgery_protection
end
end发布于 2011-07-29 12:38:08
要在应用程序中禁用它,可以将以下行添加到config/application.rb:
config.action_controller.allow_forgery_protection = false发布于 2012-02-04 19:56:43
对于外部urls,您可以按如下方式将其转换为:
<%= form_for @invoice, :url => external_url, :authenticity_token => false do |f|
...
<% end %>来源:http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for
https://stackoverflow.com/questions/5074945
复制相似问题