lundi 26 janvier 2015

Ember-CLI and Rails: No 'Access-Control-Allow-Origin' header error

I am trying to build an app with Ember-CLI (ember.js) and Rails 4.2.0. I am keeping the Ember and Rails codebases separate, so I have enabled CORS with the rack-cors gem. I keep getting the following errors when the Ember app makes a request to the Rails api:



406 Not Acceptable


And:



No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:4200' is therefore not allowed access.


And this on the Rails side:



Processing by CustomersController#index as HTML
Completed 406 Not Acceptable in 2ms

ActionController::UnknownFormat (ActionController::UnknownFormat):
app/controllers/customers_controller.rb:9:in `index'


The request Accept header is:



Accept:application/json, text/javascript, */*; q=0.01


And my controller action is:



def index
@customers = Customer.all

respond_to do |format|
format.json { render json: @customers }
#format.js { render json: @customers } Tried this too
end
end


I also have a customer_serializer using the active_model_serializer gem.


Any help will be greatly appreciated!





Aucun commentaire:

Enregistrer un commentaire