我已经解决了如何禁用控制器中的authenticity_token但rails仍然在表单中创建字段.我如何关闭它作为我发布表单的服务器需要一组非常具体的字段名称.
Ale*_*eth 16
在3.2.x之后的rails中,您可以将参数传递给表单生成器,如另一个答案所示:
form_for @invoice, :url => external_url, :authenticity_token => false do |f|
...
<% end %>
Run Code Online (Sandbox Code Playgroud)
在任何rails版本中,您可以在config/application.rb中全局禁用,如另一个答案:
config.action_controller.allow_forgery_protection = false
Run Code Online (Sandbox Code Playgroud)
在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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7224 次 |
| 最近记录: |