Rails: routes and special characters like dots – flip's

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

11 Responses to “Rails: routes and special characters like dots”

  1. Hi, I have got the same problem. Did you find a solution ?!

  2. you’re funny 😉 this post contains the solution

  3. 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?

  4. 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


  5. @filipe:
    No. I’ve found no conflicts or limitations in my apps yet.

    It’s :requirements, not :requeriments. This should fix it .

  6. 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..



  7. Hi flip,

    Danke für den Post =P This won’t work with the @ sign. Any idea?

  8. […] to this guy and this guy, who led me in the right […]

  9. Hey there. This does not work in Rails 3 anymore, so I wrote a small follow-up over here :



  10. Nice man, Thanks. Do you know how to do it but with bars (/) ? Thanks!

  11. Hi filp,

    Thank you, It’s working fine for me 🙂

Leave a Reply