我已经使用网站上提供的gems用Ember js设置了Rails 4应用程序

gem 文件

gem 'ember-rails'
gem 'ember-source', '1.2.0'

entry_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)

09-10 07:27
查看更多