Skip to content

Instantly share code, notes, and snippets.

@abelmartin
Last active August 29, 2015 14:01
Show Gist options
  • Save abelmartin/802ed23e818850d242fd to your computer and use it in GitHub Desktop.
Save abelmartin/802ed23e818850d242fd to your computer and use it in GitHub Desktop.
AngularJS CSRF token stuff
class ApplicationController < ActionController::Base
#Deailing with AngularJS CRSF issues
#...
protect_from_forgery with: :exception
after_action :set_ng_csrf_token
#...
protected
# Dealing with CSRF token issues.
def set_ng_csrf_token
cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
end
def verified_request?
super || form_authenticity_token == request.headers['X-XSRF-TOKEN']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment