I have an array of user IDs that I need to access in several places (multiple controllers, not only the UsersController). The actual user IDs in the array are selected dynamically by the admin of the system. That is, the admin is selecting a subset of users, and then I need to be able to work with that subset in other areas of the program.
Here are options I’ve considered so far for handling this (with the drawback in parathesis):
- store as session variable (cookies)
- use Flash (not meant to store anything other than error/message text)
- create a model for dynamic variables, store/delete them in the database as needed (feels hacky, and difficult if multiple admins on system simultaneously)
- add a boolean column to the User model for when admin selects user (won’t
work with multiple admins accessing system simultaneously)
- from the original controller, after a subset of users is chosen then
"redirect_to" AnotherController#create method that accepts/expects
POST method (hacky, and complicates the create method)
- use global variables (don’t think this will work with multiple admins)
And perhaps there are other ways. My goal was to avoid storing anything client side and to avoid hacks (I want to learn the rails way). I do not think instance variables will work because they are bound to a particular class, and the variables I need must be available in different classes (different controllers).
Does anyone have advice / best practices for handing this situation in rails?