我使用网站上提供的宝石设置了Ember js的Rails 4应用程序
的Gemfile
gem 'ember-rails' gem 'ember-source', '1.2.0'
entries_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/
它仍然是跨域的吗?我如何验证此请求.
那里有很多与这个问题相关的链接
http://blog.waymondo.com/2012-12-18-ember-dot-js-and-rails-authentication-gotchas/
$ -> token = $('meta[name="csrf-token"]').attr('content') $.ajaxPrefilter (options, originalOptions, xhr) -> xhr.setRequestHeader('X-CSRF-Token', token)