I'm new to using rails as an api with an Emberjs front-end. I'm getting a 'Completed 422 Unprocessable Entity' and Can't verify CSRF token authenticity whenever I try to do a POST request
I've seen a couple of posts and solutions saying to insert this function
$(function() {
var token = $('meta[name="csrf-token"]').attr('content');
return $.ajaxPrefilter(function(options, originalOptions, xhr) {
return xhr.setRequestHeader('X-CSRF-Token', token);
});
});
Where is the appropriate place to implement CSRF in an ember-cli project?
UPDATE: 10/1/2015
my app/adapters/application.js looks something like this now:
import DS from 'ember-data';
export default DS.ActiveModelAdapter.extend({
headers: Ember.computed(function(){
var token = Ember.$('meta[name="csrf-token"]').attr('content');
return {"X-CSRF-Token": token};
})
});
However, i'm still getting the same error messages...
headers
hash to do this. – elithrar