本文介绍了需要实现#cache!如果要使用Cloudinary :: CarrierWave :: Storage作为缓存存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试上传图片如果要使用Cloudinary :: CarrierWave :: Storage作为缓存存储区,则需要实现#cache!时出现此错误。
它突出显示了控制器中的这部分代码:

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

我正在使用Carrierwave将照片上传到cloudinary。
我的配置文件中有一个cloudinary.yml文件,而初始化程序中有一个cloudinary.rb。

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

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


company.rb

class Company < ApplicationRecord
  mount_uploader :identitylogo, IdentitylogoUploader
end






companies_controller.erb


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


_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


_show.html.erb

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

我注意到链接已生成,但文件未上传到cloudinary。

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

推荐答案

已将 config.cache_storage =:file 添加到载波初始化程序,并且错误消失了。 / p>

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

CarrierWave.configure do |config|
 config.cache_storage = :file
end

这是更改的提交旧行为:

Here is the commit that change the old behavior : link

这篇关于需要实现#cache!如果要使用Cloudinary :: CarrierWave :: Storage作为缓存存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 05:50