Which is the proper way to upload an image from an

2019-08-28 05:08发布

问题:

I want to download to a MOdel the image from an url: I already read Save image from URL by paperclip but first I run into this error:

    Paperclip::Error: Page model missing required attr_accessor for 'picture_file_name'

afterwards , I added the attr_accessible parameter and run into this other error:

    RuntimeError: `attr_accessible` is extracted out of Rails into a gem

I now added also the protected_attributes to no success.. This is how my model is reading right now:

require 'open-uri'
class Page < ActiveRecord::Base
has_attached_file :picture

#Get the picture from a given url.
def save_picture_from_url()
    self.picture = URI.parse(self.image_url)
end
end

SOLVER

I found my own solution. THe errors were do to proceeding without reading Paperclip's guide.

Firstly I had to install imagemagick

Secondly I had to add a migration for the model Page to add the attachment

回答1:

I found my own solution. THe errors were do to proceeding without reading Paperclip's guide.

Firstly I had to install imagemagick

Secondly I had to add a migration for the model Page to add the attachment