Routing error with: username in url

I have a Rails 3 question. I want my users browsing page to show the url app.com/people/username.

Route

resources :users  
match "/people/:username" => 'users#show', :as => :profile

It works, but if the username begins with "." (period) I have an error:

No matching routes "/people/.G"

and

<%= link_to current_user.username, profile_path(current_user.username) %>

throws an exception:

There are no route mappings {: controller => "users" ,: action => "show" ,: username => ". G"}

Sorry for my english, thanks!

+3
source share
1 answer

I don't think starting with is .supported by default in rails routes. You can do something like

match "/people/:username" => 'users#show', :as => :profile, :username => /[\.a-zA-Z0-9_]+/

., a-z, A-Z, 0-9 and _ .

+1

Source: https://habr.com/ru/post/1796492/


All Articles