Skip to content

Instantly share code, notes, and snippets.

@youngbrioche
Created July 13, 2009 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youngbrioche/146379 to your computer and use it in GitHub Desktop.
Save youngbrioche/146379 to your computer and use it in GitHub Desktop.
n-level tree based hierarchical URLs with Rails and acts_as_tree
## n-level tree based hierarchical URLs with Rails and acts_as_tree
## be free to adopt this to acts_as_nested_set or whatever
# routes.rb
map.article_deeplink ':locale/*path/:slug', :controller => 'articles', :action => 'show'
# generate the url
# the array building function should be moved into an instance method
article_deeplink_path(:path => @article.ancestors.reverse.map(&:slug), :slug => @article.slug)
# params which are generated, *path gets globbed
# {:action=>"show", :path=>["ruby_on_rails_20_installieren", "knowhow"], :slug=>"test-2", :controller=>"articles"}
# controller
def show
Article.find_by_slug(params[:slug])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment