Skip to content

Instantly share code, notes, and snippets.

@he-and-her
Created January 5, 2015 18:07
Show Gist options
  • Save he-and-her/1f5c2d30eda01ac20bb6 to your computer and use it in GitHub Desktop.
Save he-and-her/1f5c2d30eda01ac20bb6 to your computer and use it in GitHub Desktop.
Rails 4 solution for "Can't verify CSRF token authenticity” json requests
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session,
if: Proc.new { |c| c.request.format =~ %r{application/json} }
end
@glennposadas
Copy link

Thanks for this solution though it has been 8 years already, this helped me finish off my tinkering task (I'm not a backend guy nor a RoR guy.).
I am currently using Rails 7.0.3.1.
The rails app connected to Braintree was throwing me this error: Can't verify CSRF token authenticity - this gist is the answer.

@bishnuthapako
Copy link

i was struggling this error "Can't verify CSRF token authenticity" since long time. Thank you so much for this solution.

@he-and-her
Copy link
Author

Thanks for this solution though it has been 8 years already, this helped me finish off my tinkering task (I'm not a backend guy nor a RoR guy.). I am currently using Rails 7.0.3.1. The rails app connected to Braintree was throwing me this error: Can't verify CSRF token authenticity - this gist is the answer.

nice to read!

@he-and-her
Copy link
Author

i was struggling this error "Can't verify CSRF token authenticity" since long time. Thank you so much for this solution.

awesome!

@dizo1
Copy link

dizo1 commented Jun 26, 2023

i am having a similar issue with google signin any help

@ismailarilik
Copy link

Is this safe?

@elikem
Copy link

elikem commented Jun 12, 2024

I was wondering the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment