2

我正在使用的應用程序(導軌4.2.7)同時使用carrierwavepaperclip在同一數據模型User(下面的模式)上的兩個不同字段上傳圖像。如何在同一個導軌模型上使用兩個不同寶石上的相同「名稱」的兩種不同方法?

create_table "users", force: :cascade do |t| 
    t.string "email" 
    t.string "first_name",    limit: 255 
    t.string "last_name",    limit: 255 
    t.string "avatar_file_name",  limit: 255 
    t.string "avatar_content_type", limit: 255 
    t.integer "avatar_file_size" 
    t.datetime "avatar_updated_at" 
    t.string "cv_file" 
end 

avatar該字段是一個紙夾對象和cv_filecarrierwave載。現在

,爲cv_file場的後臺處理,我使用carrierwave_backgrounder寶石和avatar場我使用delayed_paperclip寶石。

這兩個寶石都暴露了process_in_background處理圖像上傳到背景。因此,我的用戶模型如下所示:

class User < ActiveRecord::Base 
    # carrierwave 
    mount_uploader :cv_file, CvFileUploader 
    process_in_background :cv_file 

    # paperclip 
    has_attached_file :avatar, 
        :default_url => "default-avatar.png", 
        :styles => { 
         :thumb => ['100x100#', :jpg, :quality => 80] 
        } 
    process_in_background :avatar, processing_image_url: "default-avatar.png" 

    # ... 

end 

我在嘗試訪問應用上的任何頁面時出現此錯誤。

未定義的方法`remove_avatar?'爲

您的意思是? remove_cv_file?

任何幫助將不勝感激。謝謝!

回答

0

簡單地分叉DelayedPaperclip並更改名稱可能是值得的。除此之外,你可能嘗試擴大DelayedPaperclip和別名的方法:

module AliasDelayedPaperclip extend DelayedPaperclip alias_method :paperclip_process_in_background, :process_in_background end

我沒有測試過這一點,它可能需要一些修改的實際工作,但它至少的建議你可以追求的道路。

相關問題