sergiutruta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-08 14:21 UTC
Nested resources with RESTful Rails
Hi, I''m using RESTful in Rails, and I have an application with the following situation: I have categories, articles and comments. A category can contain many articles (one-to-many relation) and an article can have many comments (one-to-many relation). This is like nested in nested resources. My question is how do I treat this in RESTful? BTW, I''ve already implemented the code for categories and articles, I still have to add the comments and I''m not sure how. If I add comments, I''ll have to display the comments only inside the article show view and there shouldn''t be a view where I can only see some comments. Also, how do I integrate the comments_controller::index action with the articles show view? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sergiutruta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Hi, > > I''m using RESTful in Rails, and I have an application with the > following situation: > > I have categories, articles and comments. A category can contain many > articles (one-to-many relation) and an article can have many comments > (one-to-many relation). This is like nested in nested resources. My > question is how do I treat this in RESTful? > > BTW, I''ve already implemented the code for categories and articles, I > still have to add the comments and I''m not sure how. If I add > comments, I''ll have to display the comments only inside the article > show view and there shouldn''t be a view where I can only see some > comments. Also, how do I integrate the comments_controller::index > action with the articles show view?I would not think of an article as a nested resource within a category. I think of a nested resource as something that is tied to the lifecycle of the parent object. If you delete the parent, you also would want to delete the children. In this case, article would be the parent and comments would be the children because if you delete an article, you want to delete the comments. In the case of something like a blogging system, this would not be true of the category/article relationship and so I would not use a nested pattern there. mike -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I recommend you to consult this paper by Google - "RESTful Rails Development" On the second part, it shows a pretty detailed example how nested resource could be handled probably - how to revise route.rb, etc. Hope this could resolve your puzzle. Br, Xi On 10月8日, 下午5时21分, "sergiutr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <sergiutr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m using RESTful in Rails, and I have an application with the > following situation: > > I have categories, articles and comments. A category can contain many > articles (one-to-many relation) and an article can have many comments > (one-to-many relation). This is like nested in nested resources. My > question is how do I treat this in RESTful? > > BTW, I''ve already implemented the code for categories and articles, I > still have to add the comments and I''m not sure how. If I add > comments, I''ll have to display the comments only inside the article > show view and there shouldn''t be a view where I can only see some > comments. Also, how do I integrate the comments_controller::index > action with the articles show view?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sergiutruta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-08 16:10 UTC
Re: Nested resources with RESTful Rails
myst_tt, you forgot to post the link. thanks :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
http://www.google.com/url?sa=t&ct=res&cd=4&url=http%3A%2F%2Fwww.b-simple.de%2Fdocuments%2Fdownload%2F6&ei=qNUKR4G8Ip7ynAONrfWmBQ&usg=AFQjCNGNi84oAkjqPF42jgMvhyhN0bRibg&sig2=FHJY8wB74qbE3LXj_JnUzw On Oct 9, 12:10 am, "sergiutr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <sergiutr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> myst_tt, you forgot to post the link. thanks :)--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sergiutruta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-09 08:04 UTC
Re: Nested resources with RESTful Rails
I''ve read this and I understand the RESTful concept. Though it''s not obvious that I shouldn''t make the categories resources. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---