2017-09-04 72 views
0

我的Ruby on Rails項目中有以下模型,名爲ApplicationAttachment。Carrierwave遠程附件url無法創建

我也上傳了我的s3存儲桶中的文件。當我嘗試上傳圖像到我的模型,我沒有得到一個錯誤,但附件是零和remote_attachment_url不保存該文件。不知道是什麼問題。

我的代碼是這樣的

ApplicationAttachment.create!(remote_attachment_url: "http://www.jqueryscript.net/images/jQuery-Plugin-For-Fullscreen-Image-Viewer-Chroma-Gallery.jpg") 

這並不返回任何錯誤,但它不保存圖像。

class ApplicationAttachment < ActiveRecord::Base 
    mount_uploader :attachment, DeveloperReferralAttachmentUploader 
    attr_accessible :id, :attachment, :remote_attachment_url, :created_at, :updated_at 
end 

class DeveloperReferralAttachmentUploader < CarrierWave::Uploader::Base 
    storage :file 
    def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 

    def extension_white_list 
    %w(pdf jpg jpeg gif png) 
    end 
end 

如何確保remote_image_url在通過Carrierwave創建時保存。

感謝

回答

0

我想你可能想明確地將附件保存,而不是使用create

aa = ApplicationAttachment.new(
     remote_attachment_url: "http://www.jqueryscript.net/images/jQuery-Plugin-For-Fullscreen-Image-Viewer-Chroma-Gallery.jpg" 
    ) 
aa.save 
相關問題