我正在尝试使用 CarrierWave 为 Rails 3 中的数据库播种图像,但我尝试的任何方法似乎都无法正常工作,除非必须手动上传它们。
pi = ProductImage.new(:product => product)
pi.image = File.open(File.join(Rails.root, 'test.jpg'))
pi.store_image! # tried with and without this
product.product_images << pi
product.save!
有人知道如何使用 CarrierWave 播种吗?
最佳答案
原来 CarrierWave 的文档有点错误。有一段更新的代码 in the README at the GitHub repository for the project .
不过,简而言之:
pi = ProductImage.create!(:product => product)
pi.image.store!(File.open(File.join(Rails.root, 'test.jpg')))
product.product_images << pi
product.save!
关于ruby-on-rails - 使用 CarrierWave、Rails 3 上传种子文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3910162/