timpone timpone - 1 year ago 70
Ruby Question

how to assign values to an array in a block with Fabricate gem

I have the following and the hosts (second to last) line isn't working. Is this possible? How would I assign to it for the save?

venues = Venue.all
users = User.all
Fabricate.times(16, :event ) do
venue { venues.sample }
created_by { users.sample }
sales_rep { users.sample }
casting_rep { users.sample }
hosts << { users.sample(2) }

Answer Source

Unless hosts is already an array with default value of [] the << won't work.

Better might be...

hosts { [users.sample, users.sample] }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download