1

Using Rails, I have a model "User", for which the action "Show" routes to users/:name. Usually it works fine, except that when there's a period (.) in the name, the server can no longer find the record. For example, http/localhost:3000/Joe%20Jr..

How can I fix this?

routes.rb:

get 'users/:name', to: "users#show", as: 'user'
get 'users/:id/edit', to: "users#edit", as: "edit_user"
resources :users

users_controller.rb:

def create
  #...
  redirect_to user_path
end
Joe Morano
  • 1,715
  • 10
  • 50
  • 114

1 Answers1

3

Try your route as

get 'users/:name', to: 'user#show', as: 'user', constraints: { name: /.*/ }

This got us around the same problem.

Credit to Avdi Grimm's blog post "Rails 3 resource routes with dots; or, how to make a Ruby developer go a little bit insane".

Rob Olendorf
  • 561
  • 5
  • 9