Hi Emmek,

I never found anything really convincing to handle that, but facing the 
same problem I found some workaround.

So first to get a slug, I use the plugin "ActsAsUrlParam"
http://github.com/caring/acts_as_url_param

I use it on a page "model" that uses a custom acts_as_tree  (with dotted 
ids, pretty convenient to boost performances)
http://github.com/xavier/acts-as-tree-with-dotted-ids

Then I created special routes (yeah, to use with caution, I wanted to 
avoid the "/pages/" prefix )
<code>
map.resources :pages
map.page_first_level '/:slug.:format', 
:controller=>:pages,:action=>:show
map.page_second_level '/:parent_slug/:slug.:format', 
:controller=>:pages,:action=>:show
map.page_third_level '/:ancestor_slug/:parent_slug/:slug.:format', 
:controller=>:pages,:action=>:show
</code>


finally in my page helper
<code>
module PagesHelper
  def smart_page_path(page,format=nil)
    case page.depth
    when 0
      page_first_level_path(page.slug,:format=>format)
    when 1
      page_second_level_path(page.parent.slug,page.slug,:format=>format)
    when 2
      page_third_level_path(page.parent.parent.slug, 
page.parent.slug,page.slug,:format=>format)
    else
      page_path(page)
    end
  end
end

</code>
it uses the page depth to generate my nice formatted URL

as result, using smart_page_path(@page)


-Home    -> /home.html
-About   -> /about.html
---History   -> /about/history.html
---Team      -> /about/team.html
-Projects    ->  /projects.html
---Global    ->  /projects/global.html
-----Ecology  -> /projects/global/ecology.html
-----Human rights  -> /projects/global/human-rights.html
---Local           -> /projects/local.html
-Contact           -> /contact.html



BUT!!
- the extra params are just meant for SEO, you can use any routes, only 
the last slug will be used (/my-dummy-param/about.html)
- maybe it's not that good to use routes that starts from the root.... I 
always use an "admin" namespace fro my admin sections, so I never have 
much at the root anyway.


If someone has a better idea I'll be delighted to hear it.




-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to