Rails: routes and special characters like dots
Rails doesn’t seem to like dots and other special chars in its routes.
If you want to use URLs like http://www.domain.com/post/1/just_a_test.. logically the following route seems to be sensible:
map.connect '/post/:id/:title', :controller => 'forum', :action => 'show_post'
But rails won’t like the dots. Use a route like the following to allow a URL with special characters to be routed:
map.connect '/post/:id/:title', :controller => 'forum', :action => 'show_post', :requirements => { :title => /.*/ }
Keywords: dots, dot, no route matches, punkt, punkte, routes.rb, routing, route, rails, problem, won’t work
Filed under: English, Rails 1.2, Rails 2.0, Rails 2.1, Ruby, Ruby On Rails on Juli 2nd, 2008
Hi, I have got the same problem. Did you find a solution ?!
Thanks.
you’re funny
this post contains the solution
Great! Thank you, that worked out perfectly. I was using usernames in the url and many people uses dots in their usernames. Did you found any limitations or conflicts? Not even with file format?
I’m trying to apply one restriction to file downloads.. and i created a route like:
map.connect ‘/download/:id/:filename’, :controller => “attachments”, :action => “download”, :requeriments => { :filename => /.*/ }
but it doesn’t work. with urls like
localhost:3000/download/1/My-File.mp4
@filipe:
No. I’ve found no conflicts or limitations in my apps yet.
@Guilherme:
It’s :requirements, not :requeriments. This should fix it .
Thanks for atention..
sorry but when i write into your blog i did a typing error ..
i checked and still having the problem.
maybe it’s because i have a directory called ‘download’ with the same subdirectories like ‘1/My-File.mp4′
when i access with localhost:3000/download/1/My-File i can download and it’s passed through the action that restrict the downloads..
regards,
Guilherme