views:

1024

answers:

2

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.

A: 

Look into Apache's mod_rewrite module for information on directing www.mysite.com/asdf to a CGI script with the argument "asdf".

strager
+8  A: 

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 :)

Noel Walters
"then in your controller pick up the user name with params[:user_name]"Would I do this in the 'custom' action according to your example. Say: def custom # do something with params[:user_name]end
alamodey
Yes, correct. Though obviously it doesn't have to be called 'custom' I just took that name from the word 'customised' in your question.
Noel Walters