A true newbie here ^^

I'm trying to use the Faker gem to seed x number of Items/Cards in an online store project. All good except for one thing. I don't know how to seed a different image per Item/Card created.

10.times do Item.create!(title: Faker::Book.title, description: Faker::Lorem.sentence(5), price: prices.sample, image_url: Faker::LoremFlickr.image) end 

Is there a way to seed a different image for each card?

Thank you :)

1 Answer

According to the faker docs you can prefix your method call with unique like this:

10.times do Item.create!(title: Faker::Book.title, description: Faker::Lorem.sentence(5), price: prices.sample, image_url: Faker::LoremFlickr.unique.image) end 
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.