2017-08-28 74 views
7

我有RoR項目,生活在heroku上。我有bootsy(編輯器與圖像上傳funcs),我有cloudinary。 我設置了上傳器,cloudinary api鍵和初始化器(如果需要,可以顯示你)。現在,當我嘗試在bootsy中上傳圖像時 - 它會創建數據庫行,並在cloudinary中創建圖像。但是,在從bootsy JS窗口中,有空<img>Ruby on rails bootsy + cloudinary上傳圖片麻煩

ruby '2.3.1' 
gem 'rails', '~> 5.1.1' 
gem 'bootsy' 
gem 'carrierwave' 
gem 'fog' 
gem 'cloudinary', '~> 1.8.1' 

1)上傳/ bootsy/image_uploader.rb

module Bootsy 
    class ImageUploader < CarrierWave::Uploader::Base 
    include CarrierWave::MiniMagick 

    # storage Bootsy.storage 

    include Cloudinary::CarrierWave 

    def store_dir 
     "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 

    version :large do 
     process :eager => true 
     process resize_to_fit: [ 
        700, 700 
       ] 

    end 

    version :medium do 
     process :eager => true 
     process resize_to_fit: [ 
        300, 300 
       ] 
    end 

    version :small do 
     process :eager => true 
     process resize_to_fit: [ 
        150, 150 
       ] 
    end 

    version :thumb do 
     process :eager => true 
     process resize_to_fit: [ 
        150, 150 
       ] 
    end 


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

2)初始化/ bootsy.rb

Bootsy.setup do |config| 
    config.image_versions_available = [:small, :medium, :large, :original] 
    config.storage = :fog 
end 

3)模型/article.rb

class Article < ApplicationRecord 
    include Bootsy::Container 
    mount_uploader :image, Bootsy::ImageUploader 

    mount_uploader :main_image, ArticleImageUploader 
    mount_uploader :list_image, ArticleImageUploader 

end 

This what I've in browser And html code from inspect

P.S好吧,我真的不知道 - 我只是在公共存儲庫中重複這個錯誤。 https://bitbucket.org/dekakisalove/bootsy_tes/我會盡快爲這個問題增加賞金。

+0

請添加任何錯誤信息和日誌輸出,否則我們無法診斷問題。 –

+0

@Зелёный我已經展示了屏幕。沒有錯誤消息。只是一個空的img。在軌道日誌 - 一切看起來也沒問題。在cloudinary圖像創建。在數據庫行中創建 – Legendary

+0

如果您知道,還有webbrowser控制檯。 –

回答

2

此問題是由於不正確的返回值類的方法store!Cloudinary::CarrierWave::Storage

要解決此問題,您可以使用多個變種,例如:

像這樣config/initializers/cloudinary_store.rb

module CloudinaryStorage 
    def store!(file) 
    super || uploader.metadata 
    end 
end 

ActiveSupport.on_load :after_initialize do 
    Cloudinary::CarrierWave::Storage.prepend CloudinaryStorage 
end 

或像這樣的app/uploaders/image_uploader.rb

module Bootsy 
    class ImageUploader < CarrierWave::Uploader::Base 
    after :store, :reload_data 

    def reload_data(file) 
     model.reload 
    end 
    # etc.. 
+0

您好!我現在正在重新編寫這個寶石,我現在試着檢查你的解決方案,如果它的工作完美 - 我會再次增加賞金 – Legendary

+0

嘿,它運作良好,謝謝!但它不接受尺寸 - 像我可以選擇中等或小型 - 並且它載入相同的圖像 – Legendary

+0

@Legendary,我認爲,如果仔細查看bootsy gem的源代碼,您會發現它可能沒有正常工作,例如: https: //github.com/volmer/bootsy/blob/master/app/assets/javascripts/bootsy/modal.js#L27 但是圖片url的var ious版本的生成方式類似於https://github.com/cloudinary/cloudinary_gem#try-it-right-away – Vakiliy