in Rails, ApplicationController has a method called session , use session[:user_id] to retrieve the session value. Thus, if you want to use the session in lib, you need to define a method in the lib classes that access the session as a parameter.
Library / your _class.rb
class YourClass def set_session(session_) @mysession = session_ end def session return @mysession end end
A simple way is that you can use the module instead of the lib class and include the module in your controller. Then you can use session[:user_id] in the lib module in any way.
source share