Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

P.S 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.

like image 968
Legendary Avatar asked Aug 28 '17 04:08

Legendary


1 Answers

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 inapp/uploaders/image_uploader.rb

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

    def reload_data(file)
      model.reload
    end
    # etc..
like image 51
Vakiliy Avatar answered Oct 07 '22 00:10

Vakiliy