1

I'm trying to make a Chrome extension for my Rails App that sends POST data with an ajax form. But, I get the response from the server:

ActionController::InvalidAuthenticityToken in AppController#getpostdata.

So I think I need to get an authenticity token and include that in my form. Or, should I turn it off? And how?

Thanks

hansottowirtz
  • 664
  • 1
  • 6
  • 16

2 Answers2

1

You can retrieve the token using the form_authenticity_token helper in a Rails view, during a GET request..

Alternately you can disable the token, or alternately use the :null_session option as this is considered the best for APIs. Consult the documentation for further info.

thomasfedb
  • 5,990
  • 2
  • 37
  • 65
1

You can also skip the particular api method call in the controller as given below:

skip_before_filter :verify_authenticity_token, :only =>[:method_name]

maniempire
  • 791
  • 11
  • 12
  • This is dangerous and should be avoided as much as possible, it makes your app vulnerable to Cross Site Request – a3y3 Jul 01 '18 at 14:01