6

I am getting this error when trying to upload a picture "Need to implement #cache! if you want to use Cloudinary::CarrierWave::Storage as a cache storage." It highlights this part of code in my controller:

def update
  @company.update(company_params)
  redirect_to company_path(@company)
end

I am using Carrierwave to upload photo to cloudinary. I have a cloudinary.yml file with my configuration as well as a cloudinary.rb in my initializers.

identitylogo_uploader.rb

class IdentitylogoUploader < CarrierWave::Uploader::Base
  include Cloudinary::CarrierWave


  process :convert => 'png'
  process :tags => ['logo_entreprise']

  version :standard do
    process :resize_to_fill => [150, 150, :north]
  end

  version :thumbnail do
    resize_to_fit(50, 50)
  end


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

company.rb

class Company < ApplicationRecord
  mount_uploader :identitylogo, IdentitylogoUploader
end

companies_controller.erb

def update
  @company.update(company_params)
  redirect_to company_path(@company)
end

def company_params
  params.require(:company).permit(:identitylogo, :name, :industry, 
  :employees, :website)
end

_form.erb

<%= simple_form_for @company do |f| %>
  <%= f.input :name %>
  <%= f.input :industry %>
  <%= f.input :employees %>
  <%= f.input :website %>
  <%= f.input :identitylogo_cache, as: :hidden %>
  <%= f.input :identitylogo, label: false %>

  <%= f.button :submit %>
<% end %>

_show.html.erb

<img src="<%= @company.identitylogo %> " alt="Logo de 
l'entreprise">

I noticed that the link is generated yet the file is not uploaded to cloudinary.

Marek Lipka
  • 50,622
  • 7
  • 87
  • 91
  • Update: I changed the IdentitylogoUploader to add the storage line like this: ```storage :file``` The error is gone, the uploading ends but the picture is not uploaded to cloudinary! When I inspect in the browser I see the link (that takes you nowhere since there's no pic on the cloudinary) and when I check the DB I find the value for the photo like this: `identitylogo: "uploads/company/identitylogo/127.png"> ` – Ayoub Ben Thabet Jun 26 '19 at 11:31
  • Cloudinary should be able to help with this directly too - you can open a request at https://support.cloudinary.com/hc/ – Igy Jun 27 '19 at 13:44
  • @AyoubBenThabet did you have any luck finding a solution? I'm having a similar problem (but with Imagekit::Carrierwave instead of Cloudinary). – Jack Walsh Jul 10 '19 at 08:22
  • Opened an issue here https://github.com/imagekit-developer/imagekit-gem/issues/6 – Jack Walsh Jul 10 '19 at 21:13

2 Answers2

8

Added config.cache_storage = :file to carrierwave initializer and the error is gone.

CarrierWave.configure do |config|
 # For an application which utilizes multiple servers but does not need caches persisted across requests,
 # uncomment the line :file instead of the default :storage.  Otherwise, it will use the default storage as the temp cache store.
 config.cache_storage = :file
end

Here is the commit that change the old behavior : link

Kaka Ruto
  • 4,581
  • 1
  • 31
  • 39
nicovak
  • 116
  • 2
  • 4
2

Seems like the newest version of CarrierWave is not compatible with Cloudinary yet.

Check your Gemfile and Gemfile.lock. I had to remove the .rc-ending and restart the server.

William W
  • 21
  • 2