How to get twitter / friendfeed as home urls in rails?
I want to have twitter like friendly urls like http://twitter.com/username . How to do it in rails?
+2
source to share
2 answers
Probably the easiest way is to have the entire route at the bottom of the routing table. Something like:
map.connect '/:slug', :controller => 'users', :action => 'show'
Then in the custom controller ....
def show
@user = User.find_by_username(params[:slug])
end
I also recommend catching ActiveRecord::RecordNotFound
to show the 404 page. You can put something like this in ApplicationController
:
rescue_from ActiveRecord::RecordNotFound, :with => :not_found
then define a method not_found
to display the error page or whatever.
+3
source to share