Emmek on Rails wrote:
I have a model Page in my application that acts_as_tree. I want this model to keep whole structure of website.
Then I would strongly suggest awesome_nested_set instead of acts_as_tree. It makes it possible to use the DB *much* more efficiently.
I have some root nodes: home, contact, articles, etc. and the possibility of adding children to them.
I want to access these pages using slugs (Page model and new/edit forms have such attribute/field). In show action of pages controller:
if params[:slug] @page = Page.find_by_slug(params[:slug]) raise ActiveRecord::RecordNotFound, "Page not found" if @page.nil? else @page = Page.find(params[:id]) end
And routing:
map.connect ':slug', :controller => 'pages', :action => 'show'
Everything works well at the first level but how to access children pages using hierarchy of the tree and slugs?
I'm not sure. You might need to use a *glob route for the page path, then do your own parsing.
Best,