简体   繁体   中英

Ruby on rails bootsy + cloudinary upload image trouble

I have RoR project, living on heroku. I have bootsy (editor with image upload funcs) and I have cloudinary. Ive setup uploader, cloudinary api keys and initializers (can show you, if it needed). Now, when I try to upload image in bootsy - it creates database row, and create image in cloudinary. But in js window from bootsy, there empty <img>

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

1) uploaders/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) initializers/bootsy.rb

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

3) models/article.rb

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

  mount_uploader :main_image, ArticleImageUploader
  mount_uploader :list_image, ArticleImageUploader

end

这就是我在浏览器中的内容 和检查的HTML代码

PS Ok, I really have no idea - I just repeat this bug in public repository. https://bitbucket.org/dekakisalove/bootsy_tes/ I will add bounty to this question as soon as it will be possible.

This problem is due to an incorrect return value the method store! of class Cloudinary::CarrierWave::Storage

To work around this problem, you can use several variants, for example:

like this in 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

or like this in app/uploaders/image_uploader.rb

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM