Ember js和Rails 4 CSRF

Has*_*ass 2 javascript ruby ruby-on-rails ember.js ember-data

我使用网站上提供的宝石设置了Ember js的Rails 4应用程序

的Gemfile

gem 'ember-rails'
gem 'ember-source', '1.2.0'
Run Code Online (Sandbox Code Playgroud)

entries_controller.js.coffee

Tut1.EntriesController = Ember.ArrayController.extend

    addEntry: ->
        entry = @store.createRecord(Tut1.Entry,
        name: @get('newEntryName')
        winner: false
    )
    entry.save()
Run Code Online (Sandbox Code Playgroud)

我在控制台上收到此错误.

POST http://localhost:3000/entries 422 (OK) 
Run Code Online (Sandbox Code Playgroud)

它正确发布,但rails重新调整了一个"ActionController :: InvalidAuthenticityToken",这让我感到困惑,因为主机,起源和引用是相同的.

Host:localhost:3000
Origin:http://localhost:3000
Referer:http://localhost:3000/
Run Code Online (Sandbox Code Playgroud)

它仍然是跨域的吗?我如何验证此请求.

dev*_*and 6

那里有很多与这个问题相关的链接

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)
Run Code Online (Sandbox Code Playgroud)