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")
私がこれをするのを止めてください。