Assign unique subfolder routes to each user Devise and Rails -
i want give each user on application unique url like: www.mydomain.com/username. how can achieve this? searched on internet of them talking assign each user unique subdomain. in case, happen if username conflict other controllers such home or products, example.
thanks in advance,
routes resolved top bottom, ones on top more important ones down.
that said should first put routes login, content pages, etc first in file, , them following
get `/:username` => 'users#show`
and then
root :to => 'some#path'
because root should last 1 in file.
what above code route request not matched previous routes userscontroller
show action params[:username]
set. if person goes /charinten
end in userscontroller#show
params[:username]
=> charinten
.
to ensure user profiles reachable need create list of restricted keywords (ex. 'users', 'session', etc) , when user sets username make sure it's not 1 of those. there couple methods how handle invalid/restricted username, think best 1 ask user pick 1 (same if username taken)
Comments
Post a Comment