Olivier Lance wrote: > Hi, > > 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 => > 'show' > > When I want to have a link or redirect to a diagram, I'm currently doing > this: > 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 => > 'show' > > and then in DiagramsHelper, to override diagram_path and diagram_url > like this: > def diagram_path(diagram, *args) > full_diagram_path(diagram.owner, diagram, *args) > end > > 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 > "/diagrams/27". > > 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 > included? > > 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, > Olivier
Looks like nested routes would be a better approach for this You'd need map.resources :owner, :has_many => diagrams This would create this type of restful route owner_diagrams_path route_owner_diagram_path(@owner, @diagram) etc Once you have the route.rb file in place, you can run rake routes from rails_root to see all available routes -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

