I can't seed my images using shrine, unlike carrierwave the below code doesn't work.
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")
i've also tried
image_data: ImageUploader.new(:store).upload(File.open(Rails.root+"app/assets/images/seed/thor.png"))
but it returns
JSON::ParserError in Profiles#show
743: unexpected token at '#<ImageUploader::UploadedFile:0x007fd8bc3142e0>'
Is there a shrine way? I can't seem to find it anywhere.
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
Profile
class definition along with Shrine initializer and theImageUploader.rb
– Crosspollinate