Get current user id in development

How to get current user id in my controller using development?

In my controller, I have something like this:

def index me = current_user c = User.find(me) @sheets = c.time_sheets end 

I get an error: "Could not find user without identifier."

If I put a static number in User.find (), this works, but of course, this is not what I want. Any help would be greatly appreciated.

thanks!

+8
ruby-on-rails ruby-on-rails-4 devise
source share
1 answer

Replace current index action as shown below

 def index if current_user @sheets = current_user.time_sheets else redirect_to new_user_session_path, notice: 'You are not logged in.' end end 

If the user is not logged in, i.e. current_user = nil, then the user will be redirected to the login page with a flash message.

+12
source share

All Articles