简体   繁体   English

安装Carrierwave时未保存滑轨/图像

[英]Rails / image not being saved when Carrierwave is mounted

I am using the Carrierwave plugin to upload images. 我正在使用Carrierwave插件上传图像。 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? 只要安装了载波,它就会保存图像,如果我卸载Rails会像平常一样保存图像。我该如何解决?

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. 显式打开文件可能也有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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