[英]How can I use two records from the same Rails model as foreign keys in a different Rails model?
[英]How to use two different method with the same “name” from two different gems on the same rails model?
我正在使用的應用程序(導軌4.2.7)同時使用了carrierwave
和paperclip
來上傳同一數據模型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_file
是carrierwave上傳。
現在,對於cv_file
字段的后台處理,我正在使用carrierwave_backgrounder gem,對於avatar
字段,我使用的是delay_paperclip gem。
這兩個寶石都暴露了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?
任何幫助將不勝感激。 謝謝!
簡單地分叉DelayedPaperclip並更改名稱可能是值得的。 除此之外,您可能會嘗試擴展DelayedPaperclip並對方法進行別名:
module AliasDelayedPaperclip extend DelayedPaperclip alias_method :paperclip_process_in_background, :process_in_background end
我尚未對此進行測試,它可能需要進行一些修改才能真正起作用,但這至少是您可以嘗試的一種建議。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.