I used a global variable in my app for passing information before. But I got a problem and thanks everyone here suggested me to store those data in session with database.
I tried, but I found that I can’t access the session variable in Model. I googled and knew this is the Model normal behavior, RoR won’t pass the session variable to Model.
So, I would like to use that session variable in validation and also the controller….
-
how to pass the value of the
session variable into Models? or -
is there any other method for my
use case? I need a variable storing
a value, which is required in all
MVCs, and should be independent
between different concurrent users.
Thanks everyone. 🙂
If I understand you correctly, a session variable changes the way you validate the model. I believe the correct solution for this is the following:
The code has not been testet, but that’s the idea. The if argument can be the name of a method and you can do whatever you want in there. You can have various validation modes if you want. For example:
For more information, read the guide on validation.