I am new to ruby, I am trying to populate data into a form using a set
of variables in nested loops
For i in 1…2 do
project = @blah.create(:project, :blah =>…
The above is just a spinet, but works fine
For j in 1…4 do
owner = [“tim”, “alice”, “candy”]
status = [“new”, “current”, “out_of_date”, “banned”]
contact = @contact.create(:contact, :owner => owner, :status =>
status, :project = project)
If I add:
current_owner = owner[(j-1) % owner.size] it just uses the first
variable over and over again
What I am trying to accomplish:
Create two new projects
For each project I am creating 4 new forms
For each form I want to rotate through the variables for owner and
status. If I reach the end of a list of variables (only 3 for owners). I
want it to repeat through the list.
The other scenario:
For i in 1…10 do
project = @blah.create(:project, :blah =>…
For j in 1…4 do
owner = [“tim”, “alice”, “candy”]
status = [“new”, “current”, “out_of_date”, “banned”]
contact = @contact.create(:contact, :owner => owner, :status =>
status)
QUESTION: By having more projects than data for owners? do I have to do
anything special to ensure it continues to loop through owner and status
until i is done?