My database contains data for multiple years (each table has a year column). Whenever users login they have to select a year to work with.
After login, all data accessed by the user is scoped to the selected year. The selected year is stored in the session variable and in the global variable.
I am using active_admin and active_admin_import, and I want to limit importing data only to the selected year.
I do this by adding a validation in my model. First, I tried to use the session variable but I realised that the model doesn't have access to the session; therefore, I ended up putting the selected year into a $year variable.
This was working in development, but after I pushed to the production the global variable is blank within the model, and my validation doesn't work.
From what I read I understand it is a bad idea to make session data accessible to the model. I can't think about a different solution. Any suggestions?
Additional info: As the main table can store multiple years, I import into a working table (which has the validation rule for one year), then copy data to the production table.
This way, if the import data has the wrong year or multiple years, the import fails and user gets an error message.