Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 Authenticity Token

Does anyone know how the authenticity token is managed in Ruby on Rails 3? With all the unobtrusive Javascript Ruby on Rails 3 articles showing how the HTML5 data attributes are used I don't see the authenticity token anywhere.

like image 662
matsko Avatar asked Jun 15 '10 17:06

matsko


People also ask

What is authenticity token in rails?

The authenticity token is designed so that you know your form is being submitted from your website. It is generated from the machine on which it runs with a unique identifier that only your machine can know, thus helping prevent cross-site request forgery attacks.

How do I fix invalid authenticity token?

Resolution. This error can be due to corrupted cookie in your browser. Clear your browsers cache and cookies, restart the browser and try to log in. If the error remains, the problem is that your browser has blocked any cookies from or because OCLCs Zendesk User Portal.


1 Answers

You need to put this in the head section of your layout file(s):

<%= csrf_meta_tag %>

—which outputs:

<meta name="csrf-token" content="<%= form_authenticity_token %>" />
<meta name="csrf-param" content="authenticity_token" />
like image 119
John Topley Avatar answered Oct 02 '22 22:10

John Topley