Users of my app are now able to access their profile (users/show.html.erb
) like so:
domain.com/johndoe
To make that happen, I used the following code
routes.rb:
get '/:friendly_id', to: 'users#show', as: 'user'
user.rb:
extend FriendlyId
friendly_id :username, use: [:finders]
validates_uniqueness_of :username
users_controller.rb:
def show
@user = User.friendly.find(params[:friendly_id])
end
The problem is my other routes such as domain.com/explore
and domain.com/admin
no longer work since the router thinks they are usernames. Just to clarify, "explore" and "admin" are not user profiles but models of their own.
Now it throws an error like this:
can't find record with friendly id: "explore"
How can I solve this problem?