Javascript Ember js和Rails 4 CSRF
我已经使用网站上提供的gems设置了一个带有Ember js的Rails 4应用程序 gemfileJavascript Ember js和Rails 4 CSRF,javascript,ruby-on-rails,ruby,ember.js,ember-data,Javascript,Ruby On Rails,Ruby,Ember.js,Ember Data,我已经使用网站上提供的gems设置了一个带有Ember js的Rails 4应用程序 gemfile gem 'ember-rails' gem 'ember-source', '1.2.0' 条目\u controller.js.coffee Tut1.EntriesController = Ember.ArrayController.extend addEntry: -> entry = @store.createRecord(Tut1.Entry,
gem 'ember-rails'
gem 'ember-source', '1.2.0'
条目\u controller.js.coffee
Tut1.EntriesController = Ember.ArrayController.extend
addEntry: ->
entry = @store.createRecord(Tut1.Entry,
name: @get('newEntryName')
winner: false
)
entry.save()
我在控制台上得到这个错误
POST http://localhost:3000/entries 422 (OK)
它发布正确,但rails正在重新调整“ActionController::InvalidAuthenticityToken”,这让我感到困惑,因为主机、源和引用程序都是相同的
Host:localhost:3000
Origin:http://localhost:3000
Referer:http://localhost:3000/
它仍然是跨域的吗?如何验证此请求。有很多指向该问题的链接
它不是跨域请求,但是,应用程序控制器中的代码:
protect_from_forgery with: :exception
试图抵御CSRF攻击。当您发布表单时,它需要一个有效的CSRF令牌。有
解决这个问题的一个简单方法是使用。它本质上是从您的服务器请求一个令牌,然后设置适当的头,以便使用正确的CSRF令牌发出请求
protect_from_forgery with: :exception