1

Carrierwaveでファイルサイズを検証するために、これhttps://gist.github.com/chrisbloom7/1009861を試します

  1. 私が作成しましたlib/file_size_validator.rb
  2. ファイルymlにいくつかの翻訳を入れました(wrong_size、size_too_small、size_too_big、number.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 
    }

67videos_controller.rb行目です

@video = Video.create(params[:video])

私の手順とコードを修正するのを手伝ってもらえますか?

ありがとう

4

1 に答える 1