Skip to content

Instantly share code, notes, and snippets.

@uguisu-an
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save uguisu-an/a3cca53ce1ba90ec4b83 to your computer and use it in GitHub Desktop.

Select an option

Save uguisu-an/a3cca53ce1ba90ec4b83 to your computer and use it in GitHub Desktop.
AngujarJS with Rails 4: CSRF token
# 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