URL with "." which is part of a parameter, not an extension!

Hi, all!

Here’s the problem! I have a page which is supposed to display the
profile of a member given it’s username. For example:

http://www.***.com/users/ahmed.hk

Everything worked fine until some guy got the wonderfull idea to put a
“.” in his username, and then, all I get is a 404 error, for rails takes
.hk as an extension!

Any idea how to make a route ignore “.”'s ?

Thanks a lot!

Nauhaie

You can restrict what the usernames can include in the model using
validates_format_of

OR

if you want to keep funky usernames, then use the wonderful
permalink_fu plugin to add a permalink attribute to your model. Then,
your map your routes to the permalink instead of the username. It’ll
take you 10 minutes, and do all of the hard regular expression work
for you :wink:

Sudara

On Jan 18, 3:33 pm, Damaris F. [email protected]

You will have to code the names by yourself (and decode them when they
reach the controller); afar there is no way to do such ignorement.

Nauhaie N. wrote:

Hi, all!

Here’s the problem! I have a page which is supposed to display the
profile of a member given it’s username. For example:

http://www.***.com/users/ahmed.hk

Everything worked fine until some guy got the wonderfull idea to put a
“.” in his username, and then, all I get is a 404 error, for rails takes
.hk as an extension!

Any idea how to make a route ignore “.”'s ?

Thanks a lot!

Nauhaie

You can use the regexp to accept “.” as a parameter.

The most simple way is:

map.connect ‘/users/:name’, :controller => ‘users’, :action => ‘xx’,
:name
=> /.*/

On Jan 18, 2008 9:58 PM, Nauhaie N. [email protected]

sishen wrote:

map.connect ‘/users/:name’, :controller => ‘users’, :action => ‘xx’,
:name
=> /.*/

Impeccable! Thank you so much!

Nauhaie

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs