ruby-on-railsrubyfabrication-gem

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) }
end

Solution

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

    Better might be...

    hosts { [users.sample, users.sample] }