Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Some good ways of seeding data in my app?

Databases • Asked by karl

I need some seed data for my app. How do I seed Devise users, and always as images for Paperclip?

I'd probably toss everything in db/seeds.rb. Check out the ffaker gem for creating fake names and things.

If you need to create Devise users, you can just do this (but you'll have to give them passwords)

# You can optionally generate a password if you don't want to hardcode the password
# generated_password = Devise.friendly_token.first(8)

User.create(email: "[email protected]", password: "password", password_confirmation: "password")

And for paperclip images, you can use the ruby File library to open the file and assign it.

img =, 'image.png'))
User.first.update(avatar: img)

You can use Rails.root there as a helper to get the Rails directory, and then you can join in any folders and filenames you need to get the full path in Ruby. Then you open it as a File object and assign that to your paperclip attribute. That should do the trick!

Awesome, thanks so much Chris!!

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.