简体   繁体   English

如何将文件系统中的图像添加到Rails中的Paperclip模型?

[英]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: 我想做的是以下内容:

  • For every movie I retrieve from the API with an image, set it's :image attribute to be the same image just stored on my file system for that particular movie. 对于我从带有图像的API检索的每部电影,将其设置为: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.

相关问题 如何丢弃原始图像文件并使用Paperclip和Rails 3保留调整大小? - How do I throw away the original image file and just keep the resizes with Paperclip and Rails 3? Rails:如何从不相关的控制器上将Paperclip图像附件上传到数据库+强大的参数要求 - Rails: How do I upload Paperclip image attachment to a DB from an unrelated controller + Strong params requirement 如何在个人资料页面上显示回形针图像? - How do I display my paperclip image on a profile page? 在Rails中使用CkEditor,如何启用从本地文件系统上传图像? - Using CkEditor in Rails how do I enable image upload from local file system? 如何从曲别针导轨中的url保存图像 - how to save image from url in paperclip rails Windows 7上的回形针+ ImageMagick:当我向模型中的attach_file添加样式时,图像显示失败 - Paperclip + ImageMagick on Windows 7: Image display fails when I add styles to attached_file in model Rails回形针将具有哈希值的图像从一个模型复制到另一个模型 - Rails Paperclip copy image with hash from one model to another 使用回形针Rails 3使用id上传显示来自另一个模型的图像 - Show image from another model using id upload by paperclip Rails 3 如何在Rails 3中使用没有模型的回形针上传图像? - How to upload image using paperclip without model in Rails 3? Rails回形针图像到AXSLX文件 - Rails Paperclip image to AXSLX file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM