Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 : Can't verify CSRF token authenticity

When i tried to post data through my REST Client ,i am getting a warning like this

Warning :Can't verify CSRF token authenticity.

How to solve this.

like image 935
Cyber Avatar asked Dec 26 '12 10:12

Cyber


2 Answers

I believe you are trying to make a POST from a link. By default links aren't supposed to make POST requests, only GET ones. So when you try to make the connection to your server, Rails warns you about this.
One way to bypass this kind of behavior is, instead of using a link, use a form. So you can make proper POST requests to the server.
Alternatively, you can remove the protect_from_forgery line from your application_controller, so Rails doesn't do this kind of verification, but this is extremely not recommended.

like image 105
MurifoX Avatar answered Sep 21 '22 00:09

MurifoX


You could do this, (but not recommended :)), skip forgery protection

Ex: you are posting data to PostController => Create action

class PostsController < ApplicationController

   before_filter :protect_from_forgery, :except => [:create]  

   def create
        #your method
   end
end

but having said that, I'm sure there should be a better way to do what you want to do, so if you could explain what you want to do, someone could help

HTH

like image 40
sameera207 Avatar answered Sep 21 '22 00:09

sameera207