Reputation: 17589
So I remember that one time, when i was trying to do an AJAX post, I had to pass in the form_authenticity_token as one of the data to rails. For some reason, not doing so will generate some kind of error and I would get logged out immediately. Is there a way to still have this this authenticity token for form submission but not for ajax post? In other words, I dont want to pass in that autheniticy token in my post data.
Upvotes: 3
Views: 2042
Reputation: 2081
Rather than disabling authenticity token verification, you could just pass it to javascript like so:
<%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>
Then just submit AUTH_TOKEN
along with any AJAX posts.
Upvotes: 2
Reputation: 44952
Per the documentation
You can disable csrf protection on controller-by-controller basis:
skip_before_filter :verify_authenticity_token
Upvotes: 4