Reputation: 1434
I have a Rails 3 app with API to the central app that provide some data.
I've drop an API realization into lib/
folder and found I can't access session method directly. So the question - how could I access the session from library?
Upvotes: 0
Views: 82
Reputation: 474
I think that accessing to session from lib or a model is not a good idea. Session information should only be used directly from controllers;
If you need to use session information in a model or within a library, it's a better idea to process the session information in the controller and pass it as parámeters.
There are several reasons behind it (mainly OOD), but a hint to detect the problem could be that testing the object would need to create a session object, and that is not a good practice in TDD.
Upvotes: 1