Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise current_user in routes.rb

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.

like image 277
mahemoff Avatar asked Dec 26 '11 13:12

mahemoff


People also ask

How does devise Current_user work?

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.

What is Current_user?

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.


1 Answers

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
like image 144
alf Avatar answered Sep 21 '22 14:09

alf