Nathan Kleyn Nathan Kleyn - 2 years ago 78
Ruby Question

Seeding file uploads with CarrierWave, Rails 3

I'm trying to seed a database in Rails 3 with images using CarrierWave, however nothing I try seems to work short of having to upload them all by hand.

pi = => product)
pi.image =, 'test.jpg'))
pi.store_image! # tried with and without this
product.product_images << pi!

Anybody know how to seed using CarrierWave at all?

Answer Source

Turns out the documentation for CarrierWave is slightly wrong. There is a more up to date piece of code in the README at the GitHub repository for the project.

In a nutshell, though:

pi = ProductImage.create!(:product => product)!(, 'test.jpg')))
product.product_images << pi!
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download