Skip to content

Instantly share code, notes, and snippets.

@mailtruck
Forked from prognostikos/app.js
Created October 9, 2012 00:45
Show Gist options
  • Save mailtruck/3855880 to your computer and use it in GitHub Desktop.
Save mailtruck/3855880 to your computer and use it in GitHub Desktop.
AngularJS & Rails
/**
* Angular needs to send the Rails CSRF token with each post request.
*
* Here we get the token from the meta tags (make sure <%= csrf_meta_tags %>
* is present in your layout.)
*/
angular.module('myapp',[]).
// configure our http requests to include the Rails CSRF token
config(["$httpProvider", function(p) {
var m = document.getElementsByTagName('meta');
for (var i in m) {
if (m[i].name == 'csrf-token') {
p.defaults.headers.common['X-CSRF-Token'] = m[i].content;
break;
}
}
}]);
MyApp::Application.configure do |config|
# Don't mangle Angular's special variable names!
config.assets.js_compressor = Sprockets::LazyCompressor.new { Uglifier.new(:mangle => false) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment