Hi, I''ve got this nested resource which is 3 deep, and I''m getting fed up writing something along the lines of: child_path(@child.parent.grandparent, @child.parent, @child) every time I want to link to one of those children. I''m wondering how to go about drying it up. One thing that had struck me was that I could override +child_path+, along the lines of: def child_path_with_auto_parent(child) child_path_without_auto_parent(child.parent.grandparent, child.parent, child) end alias_method_chain :child_path, :auto_parent Of course, I''d have to do the same for all the named routes, which is a little laborious, but at least it tidies up the rest of my code. The question is: where would I put that chunk of code? Where are named route methods pushed in to? There appears to be a section_path in ActionController::Base, but putting this code in there didn''t appear to do the desired thing. Maybe it''s also defined in ActionView somewhere? Or is there an even better way of tidying up these _path methods so they only take a single parameter? Trying to follow through the routing code gives me a headache... Cheers, Graeme -- Graeme Mathieson Rubaidh Ltd: Scottish for Ruby on Rails <http://www.rubaidh.com/> Personal blog: <http://woss.name/> Rubaidh Ltd is a company registered in Scotland with registration number SC297029. The registered address is: Rubaidh Ltd 12d Monktonhall Terrace Musselburgh East Lothian. EH21 6ER United Kingdom --~--~---------~--~----~------------~-------~--~----~ 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 Mathie, have you tried acts_as_resource plugin? Seems like what you need. I''ve used it in a project and it worked well. -- bobe On Feb 17, 4:57 pm, "Graeme Mathieson" <mat...-1EreJd9dmddBDgjK7y7TUQ@public.gmane.org> wrote:> Hi, > > I''ve got this nested resource which is 3 deep, and I''m getting fed up > writing something along the lines of: > > child_path(@child.parent.grandparent, @child.parent, @child) > > every time I want to link to one of those children. I''m wondering how to go > about drying it up. One thing that had struck me was that I could override > +child_path+, along the lines of: > > def child_path_with_auto_parent(child) > child_path_without_auto_parent(child.parent.grandparent, child.parent, > child) > end > alias_method_chain :child_path, :auto_parent > > Of course, I''d have to do the same for all the named routes, which is a > little laborious, but at least it tidies up the rest of my code. The > question is: where would I put that chunk of code? Where are named route > methods pushed in to? There appears to be a section_path in > ActionController::Base, but putting this code in there didn''t appear to do > the desired thing. Maybe it''s also defined in ActionView somewhere? > > Or is there an even better way of tidying up these _path methods so they > only take a single parameter? > > Trying to follow through the routing code gives me a headache... > > Cheers, > > Graeme > -- > Graeme Mathieson > > Rubaidh Ltd: Scottish for Ruby on Rails <http://www.rubaidh.com/> > > Personal blog: <http://woss.name/> > > Rubaidh Ltd is a company registered in Scotland with registration number > SC297029. The registered address is: > > Rubaidh Ltd > 12d Monktonhall Terrace > Musselburgh > East Lothian. EH21 6ER > United Kingdom--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, I had, yes, but I missed the fact that it defines the helper methods in a better way. Oops! That teaches me for assuming there would be no real code in acts_as_resource/init.rb. :-) Cheers, Graeme On 17/02/07, bobes <vladimir.tuzinsky@gmail.com> wrote:> > > Hi Mathie, > > have you tried acts_as_resource plugin? Seems like what you need. > I've used it in a project and it worked well. > > -- bobe > > On Feb 17, 4:57 pm, "Graeme Mathieson" <mat...@rubaidh.com> wrote: > > Hi, > > > > I've got this nested resource which is 3 deep, and I'm getting fed up > > writing something along the lines of: > > > > child_path(@child.parent.grandparent, @child.parent, @child) > > > > every time I want to link to one of those children. I'm wondering how > to go > > about drying it up. One thing that had struck me was that I could > override > > +child_path+, along the lines of: > > > > def child_path_with_auto_parent(child) > > child_path_without_auto_parent(child.parent.grandparent, > child.parent, > > child) > > end > > alias_method_chain :child_path, :auto_parent > > > > Of course, I'd have to do the same for all the named routes, which is a > > little laborious, but at least it tidies up the rest of my code. The > > question is: where would I put that chunk of code? Where are named > route > > methods pushed in to? There appears to be a section_path in > > ActionController::Base, but putting this code in there didn't appear to > do > > the desired thing. Maybe it's also defined in ActionView somewhere? > > > > Or is there an even better way of tidying up these _path methods so they > > only take a single parameter? > > > > Trying to follow through the routing code gives me a headache... > > > > Cheers, > > > > Graeme > > -- > > Graeme Mathieson > > > > Rubaidh Ltd: Scottish for Ruby on Rails <http://www.rubaidh.com/> > > > > Personal blog: <http://woss.name/> > > > > Rubaidh Ltd is a company registered in Scotland with registration number > > SC297029. The registered address is: > > > > Rubaidh Ltd > > 12d Monktonhall Terrace > > Musselburgh > > East Lothian. EH21 6ER > > United Kingdom > > > > >-- Graeme Mathieson Rubaidh Ltd: Scottish for Ruby on Rails <http://www.rubaidh.com/> Personal blog: <http://woss.name/> Rubaidh Ltd is a company registered in Scotland with registration number SC297029. The registered address is: Rubaidh Ltd 12d Monktonhall Terrace Musselburgh East Lothian. EH21 6ER United Kingdom --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---