[英]How do I add an image from my file system to a model with Paperclip in Rails?
I'm building an app for reviewing movies. 我正在构建一个用于审核电影的应用。 I've cached a lot of movie data from an API.
我从API中缓存了很多电影数据。 Essentially I have a movie model which has an
:image
attribute for Paperclip. 基本上我有一个电影模型,其中包含
:image
Paperclip的:image
属性。 What I've done is cache the remote image for each movie from the API onto my file system using a rake task. 我所做的是使用rake任务将API中每部电影的远程图像缓存到我的文件系统中。 What I would like to do is the following:
我想做的是以下内容:
:image
attribute to be the same image just stored on my file system for that particular movie. :image
属性为刚存储在我的文件系统上的特定电影的相同图像。 Is something like this possible with Paperclip? 使用Paperclip可以实现这样吗? Or do I need to look into something else?
或者我是否需要研究其他内容?
With my current code, I can get reference to each image object but would Paperclip allow me to set the value of my model's :image attribute to the raw image object? 使用我当前的代码,我可以获得对每个图像对象的引用,但Paperclip是否允许我将模型的:image属性的值设置为原始图像对象?
Yeah, shouldn't be a problem. 是的,不应该是一个问题。
movie = Movie.first
movie.image = File.open("...")
movie.save!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.