Created
August 11, 2008 18:17
-
-
Save spohlenz/4912 to your computer and use it in GitHub Desktop.
Integrate jQuery with Rails' forgery protection and respond_to
This file contains 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
<head> | |
<%= define_js_authenticity_token %> | |
</head> |
This file contains 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
$.ajaxSetup({ | |
data: { authenticity_token: AUTHENTICITY_TOKEN }, | |
beforeSend: function(xhr) { | |
xhr.setRequestHeader("Accept", "text/javascript") | |
} | |
}); |
This file contains 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
def define_js_authenticity_token | |
javascript_tag("var AUTHENTICITY_TOKEN = '#{form_authenticity_token}';") if protect_against_forgery? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment