NameError wile将config.action_view.embed_authenticity_token_in_remote_forms添加到true

时间:2016-10-18 09:38:23

标签: ruby-on-rails ajax nameerror authenticity-token remote-forms

我正在使用我的rails应用程序上的ajax,我收到了一个ActionController :: InvalidAuthenticityToken错误。

我读了这个

  

config.action_view.embed_authenticity_token_in_remote_forms允许你   在表单中设置authenticity_token的默认行为   远程:是的。默认情况下,它设置为false,表示远程   表单不包含authenticity_token,这在以下情况下很有用   你正在片段缓存表单。远程表单获得真实性   从meta标签,除非你支持,否则嵌入是不必要的   没有JavaScript的浏览器。在这种情况下,你可以通过   authenticity_token: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' ;: undefined local variable or method config' for main:Object(NameError)

我把它放错了地方吗?

这是my github

1 个答案:

答案 0 :(得分:0)

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