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.

1

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

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!
1

nop

I missed the following line in my application.js

//= require jquery_ujs 

I replaced it and its working..

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.