изображения, не загруженные на Cloudinary с Solidus и active_storage

я создал магазин.

я размещаю изображения на 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/среды/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'

хранилище.yml

test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>

cloudinary:
  service: Cloudinary

Я пытался проверить это локально, маг появляется в приложении, но не в системе хостинга.

конфиг/окружения/развитие.rb

 config.active_storage.service = :cloudinary

конфиг/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

Спасибо за вашу помощь


person AnnABlue    schedule 11.02.2021    source источник


Ответы (2)


Не могли бы вы отправить заявку с указанием имени вашего облака, чтобы я мог провести расследование для вас? Лучший, Мо

person user13764453    schedule 12.02.2021

я нахожу решение

интегрировать 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 нужны рельсы ›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

веселье.rb

# Enable Paperclip adapter for attachments on images and taxons
  config.image_attachment_module = 'Spree::Image::ActiveStorageAttachment'
  config.taxon_attachment_module = 'Spree::Taxon::ActiveStorageAttachment'

хранилище.yml

....
cloudinary:
  service: Cloudinary

config/окружения/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

person AnnABlue    schedule 12.02.2021