简体   繁体   中英

Rails / image not being saved when Carrierwave is mounted

I am using the Carrierwave plugin to upload images. It works fine, but if I try to save an image from the controller using

Article.create(:image => 'sample.png')

It doesent save the image as long as carrierwave is mounted, if I un-mount Rails will save the image like normal.. How can I solve this?

This is how I do it, and it works in my seeds at least :

Article.create(:image => File.open(Rails.root.join("app", "assets", "images", "sample.png"))

As you can see, make sure to provide the full path to the file. Explicitly opening the file may help too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM