如何将本地文件上传到Carrierwave模型? [英] How to upload a local file to a Carrierwave model?

查看:55
本文介绍了如何将本地文件上传到Carrierwave模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Carrierwave来处理图像上传,但是我没有使用表单,而是使用服务器中的本地文件。

I'm using Carrierwave to handle image uploads, but I'm not using a form, instead I use local files in the server.

如何制作

@user = User.first
image_path = "/tmp/pic-s7b28.jpg"

@user.image = image_path
@user.save!


推荐答案

@user = User.first
image_path = "/tmp/pic-s7b28.jpg"

@user.image = File.open(image_path)
@user.save!

您可以在载波自述文件

这篇关于如何将本地文件上传到Carrierwave模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆