开发者

ActiveResource client not behaving as expected

开发者 https://www.devze.com 2022-12-14 08:26 出处:网络
I have this code: require \'rubygems\' require \'activeresource\' ActiveResource::Base.logger = Logger.new(\"#{File.dirname(__FILE__)}/exercises.log\")

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消