【发布时间】:2020-12-06 04:29:06
【问题描述】:
我在尝试保存我的记录时发现数据库被锁定。我正在尝试在 Rails 中写一个简单的博客。拥有一个包含属性、标题、图像和内容的文章模型。我以前没有遇到过这个错误。我正在使用carrierwave作为图像上传器gem。请问,我做错了什么?
图片上传文件
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Create different versions of your uploaded files:
version :full do
process resize_to_fit: [650, 650]
end
version :thumb do
process resize_to_fit: [200, 200]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_whitelist
%w(jpg jpeg png)
end
end
文章模型
class Article < ApplicationRecord
belongs_to :author, class_name: 'User'
mount_uploader :image, ImageUploader
validates_presence_of :title, :text
end
【问题讨论】:
-
这不是因为我在发布此问题之前已经完成了解决方案
-
帮自己一个忙,如果可以的话,使用一个真正的数据库,Postgres 与 Rails 配合得很好,Mysql 也很好,两者都很容易设置。
-
谢谢。我做到了,它现在可以工作了
标签: ruby-on-rails sqlite activerecord carrierwave image-upload