0

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

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
blogofsongs
  • 2,527
  • 4
  • 21
  • 26

1 Answers1

1

Move this block:

  exercises = Exercise.find(:all)

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

OUTSIDE of the class definition.

john
  • 24
  • 1