i want to access user login id (whenever he/she loggedin?) in some other controller i tried so many methods
+1
A:
Define a current_user
method in your ApplicationController
class ApplicationController < ActionController::Base
helper_method :current_user
def current_user
# ...
# return an instance of User class
# can be just:
# @current_user ||= User.find(session[:user_id])
# if you set session[:user_id] when the user logs in
end
end
This way you can access current_user.id
inside other controllers.
j.
2010-07-09 13:35:49
You don't answer the question because it's assume he use some authentication plugin
shingara
2010-07-09 13:44:38
I didn't assume he's using any plugins. If he has a login action, he's keeping the `user_id` somewhere. This is everything I've assumed.
j.
2010-07-09 14:19:29
Yes, regardless of whether he's using an authentication plugin, it's still perfectly valid to define `current_user`, and more than likely he is using a plugin anyway.
Karl
2010-07-09 16:35:31
+1
A:
You need use session.
You put your user id in session after login
session[:user_id] = user.id
And in all of your controller you can fetch you userid from this session
User.find(session[:user_id])
shingara
2010-07-09 13:44:04