How do you pass parameters in a URL? I'm trying to design a login system similar to Twitter's. Notice how you can either login to the main page of www.twitter.com or you can go directly to customised pages such as www.twitter.com/lancearmstrong and www.twitter.com/rails . That's exactly what I need for my project. Thanks.
1597 次
2 回答
8
in config/routes.rb create a rule like this:
map.connect '/:user_name', :controller => 'login', :action => 'custom'
or somethjing similar.
then in your controller pick up the user name with params[:user_name]
This should go at the end of the file near the default rules. The system chooses the first route that matches the incoming URL. so if you have a rule like:
map.connect '/foo', :controller => 'foo', :action => 'bar'
it will need to come before the login rule. - bear in mind that if you do this you will have to disallow 'foo' as a username :)
于 2009-01-24T09:34:42.577 回答
0
Look into Apache's mod_rewrite module for information on directing www.mysite.com/asdf to a CGI script with the argument "asdf".
于 2009-01-24T03:27:06.860 回答