I have this code:
require 'rubygems'
require 'activeresource'
ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/exercises.log")
class Exercise < ActiveResource::Bas开发者_如何学Goe
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
Move this block:
exercises = Exercise.find(:all)
ex = Exercise.find(741)
ex.name += "_TEST"
ex.save
OUTSIDE of the class definition.
精彩评论