David Medinets
David Medinets

Reputation: 5618

How Do I Authenticate to ActiveResource to Avoid the InvalidAuthenticityToken Response?

I created a Rails application normally. Then created the scaffold for an event class. Then tried the following code. When run it complains about a InvalidAuthenticityToken when the destroy method is executed. How do I authenticate to avoid this response?

require 'rubygems'
require 'activeresource'

class Event < ActiveResource::Base
  self.site = "http://localhost:3000"
end

e = Event.create(
  :name => "Shortest Event Ever!",
  :starts_at => 1.second.ago,
  :capacity => 25,
  :price => 10.00)

e.destroy

Upvotes: 2

Views: 1306

Answers (2)

John Duff
John Duff

Reputation: 38588

Rails only requires this when you're requesting html, if you're requesting xml (possibly anything other than html?) it doesn't check for that. Looks like the destroy action for your server needs an xml response and the problem should go away.

Upvotes: 2

David Medinets
David Medinets

Reputation: 5618

I found an answer to this issue which works since I am writing a command-line application. I added the following to my controller:

  # you can disable csrf protection on controller-by-controller basis:
  skip_before_filter :verify_authenticity_token

Upvotes: 2

Related Questions