2013-04-28 74 views
1

缺少我试试这个https://gist.github.com/chrisbloom7/1009861用于验证文件的大小上carrierwaveCarrierwave翻译上验证文件大小

  1. 我创建lib/file_size_validator.rb
  2. 我已经把一些transalation到文件阳明海运(wrong_size,size_too_small,size_too_big,数量。 human.storage_units.units.mb)
  3. require 'file_size_validator'到我的模型
  4. 重启服务器等...

没什么忽视

但是当我尝试将视频上传大小为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]) 

能否请你帮我纠正我的脚步,我的代码?

感谢

回答

0

你在你的翻译文件嵌套错误。它应该是

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"