Which is the proper way to upload an image from an external url with Paperclip on rails 4?

北城以北 提交于 2019-12-13 20:47:56

问题


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



来源:https://stackoverflow.com/questions/22053942/which-is-the-proper-way-to-upload-an-image-from-an-external-url-with-paperclip-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!