I have a model Page in my application that acts_as_tree. I want this
model to keep whole structure of website. 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?
Example structure:
Home (pages/1)
Articles(pages/2)
----Article1 (pages/5)
----Article2 (pages/6)
Contact(pages/3)
About (pages/4)
I need this kind of access especially in ‘Articles’ node. I’d like to
access several article using mydomain.com/articles_slug/article1_slug.
What is the nice way to do it? Could you post some helpful links or
write solution? Any help appreciated.