-
-
Save freshtonic/5334209 to your computer and use it in GitHub Desktop.
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
# Set up the application | |
app = angular.module('ratingRampage', []) | |
# This is an injectable property | |
app.value 'Authentication', {} | |
# Add a directive so that if we see a csrf-token attribute, this gets set | |
app.directive 'csrfToken', (Authentication) -> | |
(scope, element, attrs) -> | |
Authentication.csrf_token = attrs.csrfToken | |
# Some service, which needs to make a POST request | |
app.factory 'Rating', ($http, Authentication) -> | |
class Rating | |
constructor: (@film) -> | |
save: (rating) -> | |
# Add the authenticity_token as a POST param | |
$http.post(@film.rating_url, | |
authenticity_token: Authentication.csrf_token, | |
rating: rating | |
).success => @saved() | |
saved: -> #... |
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
<div ng-app="ratingRampage' csrf-token="<%= form_authenticity_token %>"> | |
<!-- Your app code goes here --> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment