Nathan Kleyn Nathan Kleyn - 4 months ago 18
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?


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!