0

My question is similar to this question. Though I have not been able to figure it out yet. I want to be able to find the user id from the session. I understand that this can only be done within the controller, though I need this for a model method called Activity.log...

In my controller, I have the following:

@current_user = User.find(session[:user_id])
user_id = @current_user.id
Activity.log(user_id)

I hope that I am at least on the right track, and from the other SO question I have linked to, I have assumed that sessions is still the best way to achieve this, though I am open to suggestions. Thanks!

Community
  • 1
  • 1
tob88
  • 2,151
  • 8
  • 30
  • 33

1 Answers1

0

As indicated by @Bohdan, you may want to shorten your code a bit like this:

Activity.log( session[:user_id] )

In your case, you don't have to rely on ActiveRecord mechanisms.

Arnaud Leymet
  • 5,995
  • 4
  • 35
  • 51