2009-10-30 4 views

Répondre

0

À la fin de vos itinéraires:

map.with_options :controller => 'pages' do |pages| 
    pages.show_page    ':id',    :action => 'show' 
    pages.show_page_with_parent ':id/:parent_id', :action => 'show' 
    end 

Si vous baguette pour générer un lien vers elle:

show_page_with_parent_path(:id => page.name, :parent_id => page.parent.name) 

Ceci, bien sûr, en supposant que la clé de limace est le nom.

Vous pouvez, bien sûr, personnaliser davantage cette solution, avec une fonction d'assistance:

EG:

def custom_show_page_path(page) 
    if page.parent.nil? 
    show_page_path(:id => page.name) 
    else 
    show_page_with_parent_path(:id => page.name, :parent_id => page.parent.name) 
    end 
end 
Questions connexes