Screen name trick in Rails routes
You must have seen http://twitter.com/legalizenet where legalizenet is my screen name and I get a first context on twitter.com like every user. Its just one line of definition in the Rails routes.rb file. Just add following map.connect ‘:screen_name’, :controller => “<somecontroller>”, :action=> “<someaction>”(Note: replace <somecontroller> with right controller name and <someaction> with a right action in that controller)e.g it might look like map.connect ‘:screen_name’, :controller => “profile”, :action=> “home”This will tell rails engine , whenever there is a url like http://<hostname>/<screen_name> send request to profile_controller.rb’s “home” action. and then in home action method just do followingparams[:screen_name] and process it accordingly.Sweet isn’t it?
Comments
Leave a Reply