Skip to content

Instantly share code, notes, and snippets.

@styx
Forked from prognostikos/app.js
Created July 6, 2013 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save styx/5940351 to your computer and use it in GitHub Desktop.
Save styx/5940351 to your computer and use it in GitHub Desktop.
/**
* 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