1
缺少我試試這個https://gist.github.com/chrisbloom7/1009861用於驗證文件的大小上carrierwaveCarrierwave翻譯上驗證文件大小
- 我創建
lib/file_size_validator.rb
- 我已經把一些transalation到文件陽明海運(wrong_size,size_too_small,size_too_big,數量。 human.storage_units.units.mb)
- 將
require 'file_size_validator'
到我的模型 - 重啓服務器等...
沒什麼忽視
但是當我嘗試將視頻上傳大小爲24MB的,我得到了錯誤:
I18n::MissingTranslationData in VideosController#create
translation missing: id.number.human.storage_units.units.mb
lib/file_size_validator.rb:51:in `block in validate_each'
lib/file_size_validator.rb:42:in `each'
lib/file_size_validator.rb:42:in `validate_each'
app/controllers/videos_controller.rb:67:in `create'
這裏的id.yml
樣子:
id:
errors:
messages:
wrong_size: "is the wrong size (should be %{file_size})"
size_too_small: "is too small (should be at least %{file_size})"
size_too_big: "is too big (should be at most %{file_size})
number:
human:
storage_units:
format: "%n %u"
units:
byte:
one: "Byte"
other: "Bytes"
kb: "KB"
mb: "MB"
gb: "GB"
tb: "TB"
這裏的video.rb
require 'file_size_validator'
class video < ActiveRecord::Base
mount_uploader :file, VideoUploader
before_save :update_file_attributes, :validatefile
before_update :update_file_attributes
validates :file,
presence: true,
:file_size => {
:maximum => 20.megabytes.to_i
}
這裏的videos_controller.rb
線67
@video = Video.create(params[:video])
能否請你幫我糾正我的腳步,我的代碼?
感謝