回形针:如何在Rails控制台中存储图片? [英] Paperclip: How to store a picture in a Rails console?

查看:172
本文介绍了回形针:如何在Rails控制台中存储图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



由于我的本地存储中有很多图片(我使用抓取工具下载了大量的图片),所以我试图在导轨控制台中存储本地图片。想要将它们存储到数据库中,利用纸夹做一些图像工作,如缩略图等。
如果我使用网页一个一个地保存新图片到数据库,这将花费大量的时间。所以我想在rails控制台(一些代码)中找到一种可以批量保存图片到数据库的方式。

解决方案

要进一步阐明@ andrea的答案:



YourPaperclippedModelHere.new(:your_paperclip_field => File.new(path,r)) code>



所以如果你的模型叫Image,你的paperclip字段是数据:



code> Image.new(:data => File.new(path_to_your_file,r))


I tried storing a local image in a rails console.

Because I have many pictures in my local storage (I use crawler to download tons of pictures), I want to store them into a database, with the benefit of paperclip to do some image job, like thumbnail etc. If I use a webpage to save new pictures to database one by one, it will cost a lot of time. So I want to find a way in rails console (some code) that can batch save-picture-into-database.

解决方案

To further clarify @andrea's answer:

YourPaperclippedModelHere.new(:your_paperclip_field => File.new(path, "r"))

So if your model is called Image and your paperclip field is data:

Image.new(:data => File.new(path_to_your_file, "r"))

这篇关于回形针:如何在Rails控制台中存储图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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