使用 Rails 4 上的 Paperclip 从外部 url 上传图像的正确方法是什么? [英] Which is the proper way to upload an image from an external url with Paperclip on rails 4?
问题描述
我想将图像从 url 下载到模型:我已经阅读了通过回形针保存 URL 中的图像但首先我遇到了这个错误:
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'
之后,我添加了 attr_accessible 参数并遇到了另一个错误:
afterwards , I added the attr_accessible parameter and run into this other error:
RuntimeError: `attr_accessible` is extracted out of Rails into a gem
我现在还添加了protected_attributes,但没有成功..这就是我的模型现在的阅读方式:
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
求解器
我找到了自己的解决方案.错误是在没有阅读 Paperclip 指南的情况下进行的.
I found my own solution. THe errors were do to proceeding without reading Paperclip's guide.
首先我必须安装 imagemagick
Firstly I had to install imagemagick
其次我必须为模型页面添加迁移以添加附件
Secondly I had to add a migration for the model Page to add the attachment
推荐答案
我找到了自己的解决方案.错误是在没有阅读 Paperclip 指南的情况下进行的.
I found my own solution. THe errors were do to proceeding without reading Paperclip's guide.
首先我必须安装 imagemagick
Firstly I had to install imagemagick
其次我必须为模型页面添加迁移以添加附件
Secondly I had to add a migration for the model Page to add the attachment
这篇关于使用 Rails 4 上的 Paperclip 从外部 url 上传图像的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!