11155
(-- --)
December 2, 2010, 10:52pm
1
I'm trying to better understand ActiveResource in Rails 3.
I have this Object that extends ActiveResource::Base, and when I use the
collection_path, and pass an argument to it, the returned URL has that
argument as params in the URL instead of creating the URL like in the
docs.
For example. The docs say
Post.collection_path #=> /posts.xml
Comment.collection_path(:post_id => 5) #=> /posts/5/comments.xml
Here is what I'm getting
Post.collection_path => /posts.xml
Comment.collection_path(:post_id => 5) #=> /comments.xml?post_id=5
I'm using Rails 3.0.1.
Thanks
~Jeremy
11155
(-- --)
December 3, 2010, 8:39am
2
Jeremy Woertink wrote in post #965832:
Post.collection_path #=> /posts.xml
Comment.collection_path(:post_id => 5) #=> /posts/5/comments.xml
Here is what I'm getting
Post.collection_path => /posts.xml
Comment.collection_path(:post_id => 5) #=> /comments.xml?post_id=5
Thanks
~Jeremy
Hi Jeremy
you are reading the doc which is for ActiveRecord::Base instance
but
you are experimenting with ActiveResource::Base instance
please read documentation for ActiveResource (not ActiveRecord)
Thani
Castlerock research Info
11155
(-- --)
December 3, 2010, 7:31pm
3
Sniper Abandon wrote in post #965916:
you are reading the doc which is for ActiveRecord::Base instance
but
you are experimenting with ActiveResource::Base instance
please read documentation for ActiveResource (not ActiveRecord)
Not true. The example shown in ActiveResource::Base is what the OP
referred to.
Here's the real issue. The example...
Post.collection_path #=> /posts.xml
Comment.collection_path(:post_id => 5) #=> /posts/5/comments.xml
...is showing that Comment is a nested resource of Post so therefore
need to match the nested resource definition in your routes.rb file...
resources :posts do
resources :comments
end
Rails Routing from the Outside InThis guide covers the user-facing features of Rails routing.After reading this guide, you will know: How to interpret the code in config/routes.rb. How to construct your own routes, using either the preferred...