Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

jon http://burningbush.us

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Create spiffy myhost/[keyword] type routing

Except that I can't figure out how to do it in routes. This is what I found.

In *config/routes/rb*, as the last route add:
 map.connect '*path', :controller => 'application', :action => 'handle_unrecog'


In *app/controllers/application.rb*, put this:
 def handle_unrecog
  #do something here, the path info is in the @params value
 end


One of my uses for this is for a del.icio.us type user viewing. IE: _http://del.icio.us/[user]_ but having it only valid for users.

I'd do something like this:
 def handle_unrec
  uname = @params['path'][0] #first part of the path
  user = User.find_by_login( uname )
  if user
   return render :controller => "user", :action => "show", :id => user
  else
   return render :controller => "user", :action => "notfound"
  end
 end


Yay!
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS