I have tried using the post to change the routes to point at the username. I know this is simple, but for some reason I can't compute it at the moment. I have tried everything on the devise documentation page as well.
Drawing username routes
I just want to have the routes layout to use the username instead of id and not have the users prefix. Like:
http://example.com/username
instead of
http://example.com/users/1
class User < ActiveRecord::Base
def to_param
username
end
end
in your controller make
@user = User.find_by_username(params[:id])
instead of
@user = User.find(params[:id])
this will make your routes like http://example.com/users/username
to make what you want, you can do route like:
resources :users, :path => '' do
# nested resources...
end
so, user_path(@user) will make url http://example.com/username but It's not a good practice, cause it's not a REST. I advise you to leave urls like http://example.com/users/username
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With