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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.