I've been sitting on an ActiveResource patch for a few weeks, waiting
to get some feedback from David.  But, I see other folks like Jeremy
are starting to use it, so I committed my patch:

http://dev.rubyonrails.org/changeset/4890

It gets all the basic operations in working order, and adds support
for prefixes.  I wasn't quite sure how to pull this off.  Right now,
I'm using a route like syntax:

# See the CHANGELOG

   # rails routing code
   map.resources :posts do |post|
     post.resources :comments
   end

   # ActiveResources
   class Post < ActiveResource::Base
     self.site = "http://37s.sunrise.i:3000/";
   end

   class Comment < ActiveResource::Base
     self.site = "http://37s.sunrise.i:3000/posts/:post_id/";
   end

   @post     = Post.find 5
   @comments = Comment.find :all, :post_id => @post.id

   @comment  = Comment.new({:body => 'hello world'}, {:post_id => @post.id})
   @comment.save

One thought I've had is splitting the prefix options from the
attributes automatically.

 @comment  = Comment.new({:body => 'hello world'}, {:post_id => @post.id})
becomes
 @comment  = Comment.new(:body => 'hello world', :post_id => @post.id)

Obviously, ActiveResource is still very raw.  I wouldn't advise it's
use unless you're going to keep on top of its development.  If this
prefix stuff works, here are a few ideas I had on extending it:

   class Post < ActiveResource::Base
     self.site = "http://37s.sunrise.i:3000/";
     has_many :comments
   end

   class Comment < ActiveResource::Base
     belongs_to :post # sets site/prefix from post
   end

   @post.comments.create(:body => '....')

   @comment.post.title

Feel free to poke around and let us know what you think.  Keep in
mind, ActiveResource isn't a general XML web service framework.  It's
merely the client version of simply_restful.  Think of it as an added
bonus for following the restful conventions.

--
Rick Olson
http://weblog.techno-weenie.net
http://mephistoblog.com
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to