Created
July 13, 2009 19:27
-
-
Save youngbrioche/146379 to your computer and use it in GitHub Desktop.
n-level tree based hierarchical URLs with Rails and acts_as_tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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