Last active
August 29, 2015 14:02
-
-
Save uguisu-an/a3cca53ce1ba90ec4b83 to your computer and use it in GitHub Desktop.
AngujarJS with Rails 4: CSRF token
This file contains hidden or 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
| # app/controllers/api/base_controller.rb | |
| class Api::BaseController < ApplicationController | |
| after_action :set_csrf_cookie_for_ng | |
| respond_to :json | |
| def set_csrf_cookie_for_ng | |
| cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery? | |
| end | |
| protected | |
| 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