I have a model with has_one_attached :picture
.
I implemented a method which should download the picture for the object
def load_picture
RestClient.get(url, :accept => 'image/jpg')
end
(url attribute is working, i.e. tested by opening in a browser, it is downloading the picture)
Trying RestClient Gem here but any other solution would work too.
After the download I try to attach with
MyModel.picture.attach(load_picture)
...but it fails. Probaly because the attachment is nil
.
My question: How to download the image using a simple get request? Do I have to call something like .attachment
on the response?