Ember.js ember-data restadapter fail to load json

前端 未结 3 1455
不思量自难忘°
不思量自难忘° 2020-12-25 08:48

Cheers! I have ember-data store:

TravelClient.Store = DS.Store.extend({
  revision: 11,
  adapter: DS.RESTAdapter.create({ bulkCommit: false, url: \"http://         


        
3条回答
  •  忘掉有多难
    2020-12-25 09:07

    I have a simple work around in Rails (that is working for me so far.) It is untidy as is, but can easily be tightened up with logic in the controllers.

    In routes.rb:

    match   ':path' => 'authentications#allow', constraints: {method: 'OPTIONS'}
    

    Which simply returns status OK to any OPTIONS request.

    def allow
      head :ok
    end
    

    And then in application_controller.rb set the Cross-origin resource sharing (CORS) headers for every request:

    before_filter :cors
    def cors
      response.headers.merge! 'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Methods' => 'POST, PUT, GET, DELETE', 'Access-Control-Allow-Headers' => 'Origin, Accept, Content-Type'
    end
    

提交回复
热议问题