所以我一直在使用铁轨,播种似乎一直运作到现在为止。现在,每次尝试播种数据库时,弹出以下错误:
ActiveRecord::RecordInvalid: La validación falló: Mainimages main image translation missing: es.errors.messages.mini_magick_processing_error
问题是我根本没有对我的Mainimages进行任何验证。此外,我不知道为什么要求翻译主图像。我已经阅读了一些类似的问题,并根据他们重新安装gem或安装Imagemagick解决了这个问题。事情是,既不工作。此外,我之前已多次播种我的数据库,即使有了mainimage,刚刚出现这个错误,这让我很困惑。
以下是seeds.rb
Event.create!(
name: "event_1",
place_name: "test_place",
organizer_id: 2,
mainimages_attributes:[{main_image: File.open(File.join(Rails.root, 'test.jpg'))}]
)
这是Mainimage模型:
class Mainimage < ApplicationRecord
belongs_to :event, optional: true
mount_uploader :main_image, MainImageUploader
end
和上传者:
class MainImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :fog
version :thumb do
process resize_to_limit: [150, 150]
process quality: 100
end
version :not_so_thumb do
process resize_to_limit: [1000, 800]
process quality: 100
end
version :large do
process resize_to_limit: [1652,1115]
process quality: 100
end
def crop
if model.crop_x.present?
resize_to_limit(600, 400)
manipulate! do |img|
x = model.crop_x.to_i
y = model.crop_y.to_i
w = model.crop_w.to_i
h = model.crop_h.to_i
img.crop!(x, y, w, h)
end
end
end
def extension_whitelist
%w(jpg jpeg gif png)
end
end