CarrierWave::FormNotMultipart error when creating records using seed.rb file
Presuming that your Gem
model has the image
field as a Carrierwave uploader (that is, you've got mount_uploader :image, ImageUploader
or similar in your Gem
model), you can assign a ruby File
object to your image
attribute, not a string. Something like this:
gem = Demogem.new(data)
image_src = File.join(Rails.root, "/public/images/test2.png")
src_file = File.new(image_src)
gem.image = src_file
gem.save
In your overall code, you could either change your seed data (so your image
property in your hash was set to File.new(File.join(Rails.root, "/public/images/test1.jpg"))
or change the way you construct your new records so it doesn't use the image
by default:
gems.each do |user, data|
gem = DemoGem.new(data.reject { |k, v| k == "image" })
gem.image = new File(File.join(Rails.root, data["image"]))
unless DemoGem.where(name: gem.name).exists?
gem.save!
end
end
The CarrierWave wiki has some documentation on this, but it's not very extensive.