【发布时间】:2015-08-05 08:32:09
【问题描述】:
我正在使用 CarrierWave 上传图片。
我有 2 个模型
class Book < ActiveRecord::Base
has_many :book_attachments, dependent: :destroy
accepts_nested_attributes_for :book_attachments, allow_destroy: true, reject_if: proc { |attributes| attributes['image'].blank?}
end
class BookAttachment < ActiveRecord::Base
belongs_to :book
has_many :images
validates :image,
:file_size => {
:maximum => 3.megabytes.to_i
}
mount_uploader :image, ImageUploader
end
我需要本地化验证消息以进行图像大小验证。
我在 en.yml 中给出如下内容:
en:
activerecord:
errors:
models:
book_attachment:
attributes:
image:
too_big: The image is too big. The maximum size is 3 MB
如果图像尺寸更大,默认情况下会收到以下消息: “图书附件图片太大(最多应为 3 MB)”。
但是。我需要获取 en.yml 文件中显示的消息。
请帮忙。
【问题讨论】:
标签: ruby ruby-on-rails-4 internationalization carrierwave nested-attributes