2009-10-30 60 views

回答

0

在你的路由的结尾:

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

如果你的魔杖,以产生一个链接:

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

这当然,假设塞关键是名字。

你当然可以,进一步定制该解决方案,具有一个辅助函数:

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