I am having routes like below to delete/list an user.
map.connect 'developer/:user_name/delete',:controller=>"developers",:action=>"delete",:method=>:delete
map.connect 'developer/:user_name/list',:controller=>"developers",:action=>"list",:method=>:get
While listing the user by encoding the Dot with %2E, i can see the success response
http://localhost:3000/developer/testuser%2Ehu/list
But While trying to delete the user who containing the Dot(.), throws 404 error.
http://localhost:3000/developer/testuser%2Ehu/delete, how to fix this issue.
Avdi Grimm wrote on this subject: http://avdi.org/devblog/2010/06/18/rails-3-resource-routes-with-dots-or-how-to-make-a-ruby-developer-go-a-little-bit-insane/
You'll want to do something like this (full credit to avdi)
resources :users, :constraints => { :id => /.*/ } do
resources :projects
end
A commenter on the post says you can also do:
resources :users, :id => /.*/
I just had a similar problem, my search page url is /search/search_term. When search_term had a dot, Rails interpreted it as the request format. If I tried to search for book.html, it actually searched for book, because Rails interpreted html as the format. An unrecognized format would return an error.
In my case, the first solution from Avdi Grimm didn't work, because my search is paginated, and the page number also goes in the url (/search/book/2). The solution for me was accepting everything but a slash for the search_term (the last solution from Avdi Grimm's post):
resources :users, :constraints => { :id => /[^\/]+/ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With