我无法使用神社播种我的图像,与carrierwave 不同,下面的代码不起作用。
Profile.create! id: 2,
user_id: 2,
brand: "The Revengers",
location: "Azgaurd",
phone_number: "send a raven",
image_data: File.open(Rails.root+"app/assets/images/seed/thor.png")
我也试过
image_data: ImageUploader.new(:store).upload(File.open(Rails.root+"app/assets/images/seed/thor.png"))
但它返回
JSON::ParserError in Profiles#show
743: unexpected token at '#<ImageUploader::UploadedFile:0x007fd8bc3142e0>'
有神社方式吗?我似乎无法在任何地方找到它。
神社.rb
require "cloudinary"
require "shrine/storage/cloudinary"
Cloudinary.config(
cloud_name: ENV['CLOUD_NAME'],
api_key:ENV['API_KEY'],
api_secret:ENV['API_SECRET'],
)
Shrine.storages = {
cache: Shrine::Storage::Cloudinary.new(prefix: "cache"), # for direct
uploads
store: Shrine::Storage::Cloudinary.new(prefix: "store"),
}
配置文件.rb
class Profile < ApplicationRecord
include ImageUploader[:image]
belongs_to :user
has_and_belongs_to_many :genres
scoped_search on: [:brand]
end
image_uploader.rb
class ImageUploader < Shrine
end