Skip to content

Instantly share code, notes, and snippets.

@lujanfernaud
Created September 7, 2017 21:00
Show Gist options
  • Save lujanfernaud/a2f8b504cb23f4d6ec97fb6d8915cd36 to your computer and use it in GitHub Desktop.
Save lujanfernaud/a2f8b504cb23f4d6ec97fb6d8915cd36 to your computer and use it in GitHub Desktop.
Rails: Seed database with remote Faker images and CarrierWave
# We need to use 'remote_<object>_url' as attribute instead of '<object>'.
# Having Image, we would use 'remote_image_url: <url>'.
titles = [Faker::RockBand.name, Faker::BossaNova.artist, Faker::Book.title]
54.times do |n|
start_date = Faker::Date.between(1.day.from_now, 6.months.from_now)
end_date = start_date + 1.day
Event.create!(title: titles.sample + " ##{n}",
description: Faker::Lorem.paragraph,
start_date: start_date,
end_date: end_date,
remote_image_url: Faker::LoremPixel.image("730x411"),
organizer_id: User.all.sample.id )
end
Copy link

ghost commented Mar 2, 2020

Hey there! Working on something similar but for Rails 6, any chance you could have a look? https://gist.github.com/theweddingplanner/dfa9b547e8f08e40d2fe096754a0b0ae

Thanks!

@bartlomiejpogorzelski
Copy link

It is correct solution?

@lujanfernaud
Copy link
Author

@bartlomiejpogorzelski For my use case 5 years ago, it worked. You would need to try to see if it fits your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment