Trying to use username in my rails routes.
Routes that work:
resources :users, only: [:show, :create, :update, :destroy] get "/:username" => "users#show", as: :user get "/:username/account" => "users#account", as: :user_account get "/:username/interests", to: "users#interests", as: :user_interests get "/:username/offers" => "users#offers", as: :user_offers get "/:username/trades" => "users#trades", as: :user_trades
but now a route like:
get "/signup"
matches the rule /:username
I know that I can reorder my routes so that / registration appears earlier, but it seems a bit hacked.
Is there any way to rewrite this? Or is this the only way to have a reserved username check?
thanks
EDIT
In the end, I added a user model confirmation with reserved words. Namespacing is a good idea, but I don't want to pollute my URLs.
For the record, the Twitter namespace instead of names such as: twitter.com/i/discover (goes to Twitter) twitter.com/discover (goes to @discover profile)
Names of backup objects, such as "search", as far as I can tell
I followed Pinterest approach with code:
checks:
validate :reserved_username private def reserved_username reserved_usernames = %w[index show create destroy edit update signup interests interest item items search offers offer community about terms privacy admin map authentication] errors.add(:reserved_username, "username is reserved for the app") if reserved_usernames.include?(username) end