In my controller i have two actions: "Select_users" and "Make_something".
In “Select_users” i get a @var with a list of users (this users are generated from a search with a form in the same view) and i need to make an insert for each of those … like:
@var.each do |v|
Table.create(:atribute => v.name)
end
When i have my list of selected users i use a Submit button to send me to the “Make_something” action.
So i was thinking to “pass” the @var variable to the “Make_something” action to make this create, but I can’t use @var in “Make_something” because it’s accesible only in “Select_users”.
I read about filters but i think they cant help me with this problem.
Thanks!
If you have code common to several methods, extract it out to another method.
Alternatively, you could pass the list of IDs of the selected users in the form that posts to “make_something”. Or if you really want to persist this somehow (I assume this is some form of “multi-step form wizard” of some description), user the db, not the session – have a “wizard” model that is retained in the DB. Each step would then pass the wizard_id, and save its own values to the wizard – this could have normal AR associations (for your selected users) through relationships.