7

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.

xdazz
  • 158,678
  • 38
  • 247
  • 274
Cyber
  • 4,844
  • 8
  • 41
  • 61
  • That a look at: http://stackoverflow.com/questions/7203304/warning-cant-verify-csrf-token-authenticity-rails – Chetane Dec 26 '12 at 10:54

3 Answers3

7

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.

MurifoX
  • 14,991
  • 3
  • 36
  • 60
2

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

sameera207
  • 16,547
  • 19
  • 87
  • 152
  • I upvoted this because I wanted to know how to handle this warning, not because I wanted to skip it. Don't skip forgery protection! – Ziggy Apr 16 '14 at 23:55
1

nop

I missed the following line in my application.js

//= require jquery_ujs

I replaced it and its working..

Abhi
  • 3,361
  • 2
  • 33
  • 38