如何解决Ruby on Rails Cloudinary 错误:“Cloudinary”缺少服务适配器
我在使用 Cloudinary 时遇到问题。
当我尝试通过更新表单上传照片时,我在编辑页面上收到错误消息:
RuntimeError in ProductsController#update
Missing service adapter for "Cloudinary"
Exception Causes
LoadError: cannot load such file -- active_storage/service/cloudinary_service
我是我的 Gemfile 我有 gem 'cloudinary'
。在 Gemfile.lock
我有 cloudinary (1.2.4)
我也跑了:
rails active_storage:install
rails db:migrate
如果我在 Cloudinary::Uploader.upload()
中使用 helper rails c
,它会起作用。但在表单中它不起作用。
storage.yml
cloudinary:
service: Cloudinary
在环境开发和生产中我有
config.active_storage.service = :cloudinary
这是我的表格
edit.html.erb
<div class="container">
<%= simple_form_for(@product) do |f| %>
<%= f.input :title %>
<%= f.input :category,collection: PRODUCT_CATEGORY,label: "Type" %>
<%= f.input :price %>
<%= f.input :photo,as: :file %>
<%= f.submit class: "btn btn-primary"%>
<% end %>
</div>
我的模型
该模型还有一个名为 filename
class Product < ApplicationRecord
has_one_attached :photo
validates :title,presence: true,length: { maximum: 250 }
validates :category,inclusion: { in: PRODUCT_CATEGORY }
validates :description,length: { maximum: 500 }
validates :price,presence: true
validates :rating,inclusion: { in: PRODUCT_RATING }
end
还有我的控制器
class ProductsController < ApplicationController
skip_before_action :authenticate_user!,only: [:index]
before_action :set_product,only: %i[edit update destroy]
def edit
end
def update
@product.update(product_params)
redirect_to root_path
end
private
def set_product
@product = Product.find(params[:id])
authorize @product # For Pundit
end
def product_params
params.require(:product).permit(:title,:category,:price,:rating,:photo)
end
end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。