Andrew Cetinic
Andrew Cetinic

Reputation: 2835

Paperclip add a image in the code

I wish to use the paperclip gem to add an image that I am retrieving from an API for my user model using code.

How can I attach an image manually using code, rather than passing in parameters from a submitted form ?

Upvotes: 2

Views: 1093

Answers (1)

sevenseacat
sevenseacat

Reputation: 25029

If your model object is @bar, image field is called :logo and you want to attach foo.jpg...

@bar[:logo] = File.open('foo.jpg') should work. Or am I misunderstanding the question?

You'd need to initialize your paperclip attachments in a similar way if you were populating from seed data, for example.

Upvotes: 4

Related Questions