私はshrineを使用して画像をシードすることはできません。以下のコードは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>'
を返すには、神社の方法はありますか?私はそれをどこでも見つけることができない。モデルにShrine
、添付ファイルの属性(例えばimage_data
)を使用して
shrine.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"),
}
profile.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
神社初期化子と 'ImageUploader.rbとともに' Profile'クラス定義を共有してください。 ' –
さて、上記の追加情報を追加しました。 –
コマンドを実行するとエラーメッセージが表示されますか? –