0

我在我的 Rails 应用程序上处理 ajax,但出现 ActionController::InvalidAuthenticityToken 错误。

我读了这个

config.action_view.embed_authenticity_token_in_remote_forms 允许您在带有 remote: true 的表单中设置authenticity_token 的默认行为。默认情况下,它设置为 false,这意味着远程表单将不包含authentity_token,这在您对表单进行片段缓存时很有帮助。远程表单从元标记中获取真实性,因此除非您支持没有 JavaScript 的浏览器,否则嵌入是不必要的。在这种情况下,您可以将authentity_token: true 作为表单选项传递,或者将此配置设置设置为true。

来自RailsGuides

所以我添加config.action_view.embed_authenticity_token_in_remote_forms=true到 \config\application.rb

并重新启动rails服务器,然后发生错误

/Users/haha/railsbridge/railsfun/ruby12weeks/eat/config/application.rb:5:in':未定义的局部变量或方法配置'为 main:Object (NameError)

我是不是放错地方了?

这是我的github

4

1 回答 1

0

该行或任何配置行应该在里面Application class,即在您的 github 代码中的12行之后和行之前16

于 2016-10-18T09:42:05.073 回答