我有这段代码:
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
生成的ex.save网址为
POST http://localhost/exercises.xml
结果是创建了新记录而不是更新现有记录......
我原本希望网址是
PUT http://localhost/exercises/741.xml
当然我希望现有的记录能够更新。
任何想法在哪里看?
由于
答案 0 :(得分:1)
移动此块:
exercises = Exercise.find(:all)
ex = Exercise.find(741)
ex.name += "_TEST"
ex.save
类定义的外部。