-
-
Save mailtruck/3855880 to your computer and use it in GitHub Desktop.
AngularJS & Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} | |
} | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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