Last Updated: February 25, 2016
·
39.07K
· dpaluy

Rails 4 solution for "Can't verify CSRF token authenticity” json requests

Instead of complete turning off CSRF, you can do the following in Rails 4:

class ApplicationController < ActionController::Base
  protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
end

Related protips