使用 ActiveResource,Ruby on Rails,是否有一种干净的方法来执行以下操作:
我有房子 ActiveResource 模型和椅子 ActiveResource 模型,两者都可以有评论。我想为两者重用评论 ActiveResource 模型。
# ActiveResource wraps HTTP POST Requests to the following
# And then parsess the responses, and then creates instances of my ActiveResource models
POST http://3rd.party.restful.api.com/admin/houses/1/comments
POST http://3rd.party.restful.api.com/admin/houses/1/chairs/3/comments
我只能想到以下几点:
class Comment < ActiveResource::Base
self.site = "http://3rd.party.restful.api.com"
self.prefix = "/admin/:prefix_path/"
end
然后执行以下操作:
comment = Comment.new(:text => "some text", :prefix_path => "houses/1/chairs/3")
请阻止我这样做。