Hi. I have 3 tables, forum, post and reply. I would like to access replies with the url forums/x/posts/x/replies/x .... I have the posts nested within the forums, but if I wanted to add another layer, would I have to do this on a separate line in the routes file or simply add :has_many => :replies to what I already have: map.resources :forums, :has_many => :posts Thanks in advance! -- 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 -~----------~----~----~----~------~----~------~--~---
Is there any reason why you want to do THREE level deep nested routes? Jamis Buck provided a fairly good argument against this, last year: http://weblog.jamisbuck.org/2007/2/5/nesting-resources. If you''re still interested in doing it and I can''t disuade you: map.resources :forums do |forum| forum.resources :posts do |post| post.resources :replies end end Again, I must warn you that this leads to really ugly URLs. It''s best to only do two level deep nested routes, as in forums/1/posts and posts/1/replies/1, makes your URLs shorter and prettier. On Sun, Mar 16, 2008 at 7:28 AM, Dan Smith <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi. I have 3 tables, forum, post and reply. > I would like to access replies with the url forums/x/posts/x/replies/x > .... > > I have the posts nested within the forums, but if I wanted to add > another layer, would I have to do this on a separate line in the routes > file or simply add :has_many => :replies to what I already have: > > map.resources :forums, :has_many => :posts > > Thanks in advance! > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the reply. OK, I can add a reply to a post by using a partial, this takes away the need to nest the routes. How can I access the id of the current post and then pass it to the reply controller to fill the post_id field? Thx. -- 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 -~----------~----~----~----~------~----~------~--~---
On Sun, 2008-03-16 at 03:14 +0100, Dan Smith wrote:> Thanks for the reply. OK, I can add a reply to a post by using a > partial, this takes away the need to nest the routes. > > How can I access the id of the current post and then pass it to the > reply controller to fill the post_id field?---- doesn''t it still show the id in your URL? :id => params[:id] you can continue to add params to your form_for and pass them with the click. Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can call a before_filter to initialize the post object: before_filter :find_post and then further down (at the bottom) of your controller put: private def find_post @post = Post.find(params[:post_id]) if params[:post_id] end And that''ll initalize a post object every time the post_id has been specified. To create a reply to that post, do @post.replies.build(params[:reply]) and that will automatically pass in the post_id. On Sun, Mar 16, 2008 at 12:44 PM, Dan Smith < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Thanks for the reply. OK, I can add a reply to a post by using a > partial, this takes away the need to nest the routes. > > How can I access the id of the current post and then pass it to the > reply controller to fill the post_id field? > > Thx. > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 understand what you''re saying but for some reason the value isn''t being passed from the url to the reply controller. You have a nil object when you didn''t expect it! The error occurred while evaluating nil.replies -- 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 -~----------~----~----~----~------~----~------~--~---