views:

52

answers:

1

I have this code:

require 'rubygems'
require 'activeresource'

ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/exercises.log")

class Exercise < ActiveResource::Base
  self.site = "http://localhost"
  exercises = Exercise.find(:all)

  ex = Exercise.find(741)
  ex.name += "_TEST"
  ex.save
end

And the generated url for ex.save is

POST http://localhost/exercises.xml

The result is the creation of a new record rather than an update of eexisting record...

I would have expected the url to be

PUT http://localhost/exercises/741.xml

and of course I was expecting the existing record to be updated.

Any ideas where to look?

Thanks

+1  A: 

Move this block:

  exercises = Exercise.find(:all)

  ex = Exercise.find(741)
  ex.name += "_TEST"
  ex.save

OUTSIDE of the class definition.

john