How to add an image from my file system to a model using Paperclip in Rails?

I am creating a movie viewing application. I cached a lot of movie data from the API. Essentially, I have a movie model that has an attribute :image for Paperclip. What I did was remote image cache for each movie from the API to my file system using the rake task. I would like to do the following:

  • For each movie that I extract from the image API, set its attribute :image as the same image just stored in my file system for this particular movie.

Is this possible with Paperclip? Or do I need to look into something else?

With my current code, I can get a link to each image object, but if Paperclip allowed me to set the value of the my model: image attribute to the original image object?

+4
source share
1 answer

Yes should not be a problem.

 movie = Movie.first movie.image = File.open("...") movie.save! 
+4
source

All Articles