使用CarrierWave,Rails 3上传种子文件 [英] Seeding file uploads with CarrierWave, Rails 3
问题描述
我正在尝试使用CarrierWave在Rails 3中使用图像播种数据库,但是除了尝试手动上传所有图像外,我尝试的其他方法似乎无济于事。
pi = ProductImage.new(:product =>产品)
pi.image = File.open(File.join(Rails.root,'test.jpg')))
pi.store_image! #尝试使用和不使用此
产品。product_images<< pi
product.save!
有人知道如何使用CarrierWave进行播种吗?
结果证明,CarrierWave的文档略有错误。在项目的GitHub存储库中的自述文件中,有一个最新的代码。 总而言之: 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. 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:
这篇关于使用CarrierWave,Rails 3上传种子文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
pi = ProductImage.create!(:product => product)
pi.image.store!(File.open(File.join(Rails.root,'test.jpg')))
product.product_images<< pi
product.save!
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!
pi = ProductImage.create!(:product => product)
pi.image.store!(File.open(File.join(Rails.root, 'test.jpg')))
product.product_images << pi
product.save!