【发布时间】:2018-04-25 22:49:24
【问题描述】:
我无法使用神社播种我的图像,与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"),
}
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类定义以及 Shrine 初始化程序和ImageUploader.rb -
好的,我已经添加了上面的额外信息。
-
您在运行命令时是否收到任何错误消息?
-
不是当我运行 db:seed 时,而是当我转到配置文件时它不会加载图像。 743:'#<0x007f83204b7800>0x007f83204b7800>
标签: ruby-on-rails ruby-on-rails-5 shrine