views:

635

answers:

2

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
+1  A: 

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
David Medinets
+2  A: 

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.

John Duff