Is there any way to access the current user in routes.rb? I would like a mapping like this:
match /profile => redirect("/profiles/{current_user.name}")
env['warden']
doesn't seem to be set up, so I can't access warden.user.name
.
current_user works by storing id of current user in the application session. Most commonly session is stored in cookies. Whether or not the cookies survive browser restart depends on client's browser settings.
The CURRENT_USER() function returns the user name and host name for the MySQL account that the server used to authenticate the current client. The result is returned as a string in the UTF8 character set.
Not sure that's possible. However, you could use a controller:
def profile
if signed_in?
redirect_to user_profile_path(current_user)
else
redirect_to root_url
end
end
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