how to retrieve user name from cookie session data(RAILS) -



how to retrieve user name from cookie session data(RAILS) -

i studying ror, have partial side bar gets rendered in user dashboard area, , returning user's name in dashboard so. dashboard layout included in user controller. need utilize new controller

<h1>welcome back, <%= @user.name %> </h1>

so changed to

<h1>welcome back, <%= current_user %> </h1>

but problem instead of returning username, current_user returns this

#<user:0x007fa8ee293940>

which assuming remember_token hash. since current_user have session cookie, not sure how traverse db the username. can help me tweak current_user current session user returns username?

thanks!

here session helper

def sign_in(user) remember_token = user.new_remember_token cookies.permanent[:remember_token] = remember_token user.update_attribute(:remember_token, user.digest(remember_token)) self.current_user = user end def current_user= (user) @current_user = user end def current_user remember_token = user.digest(cookies[:remember_token]) @current_user || user.find_by(remember_token: remember_token) end

<user:0x007fa8ee293940> string representation of user object. want name property of object, similar doing before (@user.name). instead of current_user, current_user.name should it.

ruby-on-rails session authentication cookies controller

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -