未使用 Solidus 和 active_storage 上传到 Cloudinary 的图像
Posted
技术标签:
【中文标题】未使用 Solidus 和 active_storage 上传到 Cloudinary 的图像【英文标题】:images not uploaded on Cloudinary with Solidus and active_storage 【发布时间】:2021-05-15 13:54:40 【问题描述】:我创建了一家商店。
我在 Cloudinary 上托管图像。我可以在本地和生产环境中加载图像,但在云端找不到它们。
我关注: https://github.com/cloudinary/cloudinary_gem https://github.com/0sc/activestorage-cloudinary-service
宝石文件:
source 'https://rubygems.org'
git_source(:github) |repo| "https://github.com/#repo.git"
ruby '2.6.6'
gem 'rails', '~> 6.0.3', '>= 6.0.3.5'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 4.1'
gem 'sass-rails', '>= 6'
gem 'webpacker', '~> 4.0'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
gem 'bootsnap', '>= 1.4.2', require: false
gem 'solidus'
gem 'solidus_auth_devise'
gem 'cloudinary'
gem 'activestorage-cloudinary-service'
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'dotenv-rails'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
config/storage.yml
cloudinary:
service: Cloudinary
cloud_name: <%= ENV['CLOUDINARY_CLOUD_NAME'] %>
api_key: <%= ENV['CLOUDINARY_API_KEY'] %>
api_secret: <%= ENV['CLOUDINARY_API_SECRET'] %>
config/environments/production.rb
config.active_storage.service = :cloudinary
spree.rb:关于回形针的行被注释
# Enable Paperclip adapter for attachments on images and taxons
# config.image_attachment_module = 'Spree::Image::PaperclipAttachment'
# config.taxon_attachment_module = 'Spree::Taxon::PaperclipAttachment'
storage.yml
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
cloudinary:
service: Cloudinary
我尝试在本地测试它,法师出现在应用程序上,但没有出现在托管系统上。
config/environments/development.rb
config.active_storage.service = :cloudinary
config/cloudinary.yml
development:
cloud_name: xxx
api_key: 'xxx'
api_secret: xxx
enhance_image_tag: true
static_file_support: false
production:
cloud_name: xxx
api_key: 'xxx'
api_secret: xxx
enhance_image_tag: true
static_file_support: true
test:
cloud_name: xxx
api_key: 'xxx'
api_secret: xxx
enhance_image_tag: true
static_file_support: false
感谢您的帮助
【问题讨论】:
【参考方案1】:您能否提交一张标明您的云名称的工单,以便我为您进行调查? 最好的, 莫
【讨论】:
【参考方案2】:我找到了解决办法
将 cloudinary 与 active_record 集成
宝石文件
gem 'rails', '~> 6.1'
# Use Active Storage variant
gem 'image_processing', '~> 1.2'
gem 'cloudinary'
gem 'activestorage-cloudinary-service'
然后
bundle install
Active_record 需要 rails >6.1
bundle update rails
cloudinary.yml 或在您的服务器上设置环境变量
development:
cloud_name: xxx
api_key: 'xxx'
api_secret: xxx
enhance_image_tag: true
static_file_support: false
production:
cloud_name: xxx
api_key: 'xxx'
api_secret: xxx
enhance_image_tag: true
static_file_support: true
test:
cloud_name: xxx
api_key: 'xxx'
api_secret: xxx
enhance_image_tag: true
static_file_support: false
spree.rb
# Enable Paperclip adapter for attachments on images and taxons
config.image_attachment_module = 'Spree::Image::ActiveStorageAttachment'
config.taxon_attachment_module = 'Spree::Taxon::ActiveStorageAttachment'
storage.yml
....
cloudinary:
service: Cloudinary
config/environnements/production.rb
config.active_storage.service = :cloudinary
如果它引发错误。
ActiveModel::UnknownAttributeError (unknown attribute 'service_name' for ActiveStorage::Blob.):
rails active_storage:update
rails db:migrate
数据库需要为空产品,否则会引发错误
https://github.com/solidusio/solidus/discussions/3930#discussioncomment-361391
【讨论】:
以上是关于未使用 Solidus 和 active_storage 上传到 Cloudinary 的图像的主要内容,如果未能解决你的问题,请参考以下文章
如何在 MacOS 中安装 chef 12 以部署到 AWS Opsworks?
“注意:未定义的变量”、“注意:未定义的索引”、“警告:未定义的数组键”和“注意:未定义的偏移量”使用 PHP
“注意:未定义的变量”、“注意:未定义的索引”、“警告:未定义的数组键”和“注意:未定义的偏移量”使用 PHP