I’ve got troubles overriding some Rails generated URL helpers…
My site allows registered users to create some kind of diagrams online,
and then to browse all created diagrams, etc.
I’ve got a route to access a diagram created by a user:
map.diagram ‘:owner_id/:id’, :controller => ‘diagrams’, :action =>
When I want to have a link or redirect to a diagram, I’m currently doing
redirect_to diagram_path(diagram.owner, diagram) – so that :owner_id
and :id are correctly set
I want to do something so that diagram_path(diagram) would generate the
correct URL with diagram’s owner id and diagram’s id.
What I have tried to do is to rename my route:
map.full_diagram ‘:owner_id/:id’, :controller => ‘diagrams’, :action =>
and then in DiagramsHelper, to override diagram_path and diagram_url
def diagram_path(diagram, *args)
full_diagram_path(diagram.owner, diagram, *args)
It’s working well, except for one thing: the method is not available in
my controllers. Though I’ve got “helpers :all” in ApplicationController.
So, in a view, diagram_path(diagram) would give “/olance/27”, whereas a
redirect_to diagram_path(diagram) in a controller would redirect to
If I copy my overriden methods in application_controller.rb, then it
does work. So I really don’t get it, why would my helpers not be
Is there a better way to do what I’m trying to achieve? I might have
missed something in the routes mechanisms… nested routes maybe?
I’m using Rails 2.3.8 by the way.
Thanks a lot,