gpt4 book ai didi

ruby-on-rails - 需要实现#cache!如果你想使用 Cloudinary::CarrierWave::Storage 作为缓存存储

转载 作者:行者123 更新时间:2023-12-03 16:04:49 25 4
gpt4 key购买 nike

尝试上传图片时出现此错误“需要实现 #cache!如果您想使用 Cloudinary::CarrierWave::Storage 作为缓存存储。”
它在我的 Controller 中突出显示了这部分代码:

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

我正在使用 Carrierwave 将照片上传到 cloudinary。
我有一个包含我的配置的 cloudinary.yml 文件,以及我的初始值设定项中有一个 cloudinary.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

公司.rb
class Company < ApplicationRecord
mount_uploader :identitylogo, IdentitylogoUploader
end

company_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">

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

最佳答案

已添加 config.cache_storage = :file到载波初始化器,错误消失了。

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

这是改变旧行为的提交: link

关于ruby-on-rails - 需要实现#cache!如果你想使用 Cloudinary::CarrierWave::Storage 作为缓存存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56771315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com