Skip to content

Instantly share code, notes, and snippets.

@intruxxer
Created November 26, 2013 17:24
Show Gist options
  • Save intruxxer/7662385 to your computer and use it in GitHub Desktop.
Save intruxxer/7662385 to your computer and use it in GitHub Desktop.
Once I was posting a form to server and I am getting the warning of missing authenticity token.
Though form_for is adding authenticity_token filed automatically when generating form for object.
But if you are not going to use the form_for tag then you can add hidden field with token as a value.
Following is the example of adding that field in form.
<input name="authenticity_token" type="hidden" value="<%= form_authenticity_token %>" />
There is one more helper in Rails which will return you the token value. i.e. form_authenticity_token
Rather you can use the jquery function to add the token value from the meta tag. But make sure meta tag is included in you layout file. It would be something like this:
<%= csrf_meta_tag %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment