7

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.

Legendary
  • 2,243
  • 16
  • 26
  • Please add any error message and the logs output, otherwise we unable to diagnose problem. – Roman Kiselenko Aug 28 '17 at 04:54
  • @Зелёный I've showed the screen. No errors messages. Just an empty img. In rails log - everything looks ok also. In cloudinary images are created. In database row are created – Legendary Aug 28 '17 at 04:57
  • There is also webbrowser console if you know. – Roman Kiselenko Aug 28 '17 at 04:59
  • @Зелёный There are no errors, console also is empty. – Legendary Aug 28 '17 at 05:00
  • there is no magic at all, you missing something simple, I'm sure it's js problem. – Roman Kiselenko Aug 28 '17 at 05:02
  • @Зелёный In my thoughts, there are must be something for showing bootsy, that images are in cloudinary now (cause in db links for images are the same as in cloudinary) Im trying to monkey-patch it, but can't find where bootsy store it. – Legendary Aug 28 '17 at 05:03
  • bootsy implementing is #= require bootsy and = f.bootsy_area :body, class: "form-control", rows: 5 so, here is have not any manipulations with js-initialize form my side ( – Legendary Aug 28 '17 at 05:05

1 Answers1

2

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..
Vakiliy
  • 871
  • 6
  • 12
  • Hello! I was re-write this gem at all, I will now try to check ur solution and if its works perfectly - I will add bounty again – Legendary Sep 09 '17 at 11:08
  • Hey, it is working well, thanks! But it is not accepting sizes at all - like i can pick medium or small - and it is loading the same image – Legendary Sep 09 '17 at 11:14
  • @Legendary, i think, if you look at source code of bootsy gem closely, you'll see that probably it have not never worked properly, for example: https://github.com/volmer/bootsy/blob/master/app/assets/javascripts/bootsy/modal.js#L27 but image url of various versions's generated like explained in https://github.com/cloudinary/cloudinary_gem#try-it-right-away – Vakiliy Sep 09 '17 at 18:38