views:

39

answers:

1

I have a class Document (in a mongodb collection) and persist various sub classes (like Page < Document). Now I do a Document.all()- how do I generate links to the document's edit action pointing to the right controller (PageController for pages) without being verbose about it?

<%= link_to document.title, [:admin, document] %>

points to 'show;, how can I make it point to 'edit' without specifying the controller?

+3  A: 

You can prepend :edit to your resource link:

link_to document.title, [:edit, :admin, document]

It will create the proper link (i.e. /admin/page/1/edit, /admin/document/2/edit), provided that you have a route defined for each resource.

Dave Pirotte
thanks a lot. Found this nowhere in the docs...
Jan Limpens