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