I try this https://gist.github.com/chrisbloom7/1009861 for validate file size on carrierwave
- I have created
lib/file_size_validator.rb
- I have put some transalation to file yml (wrong_size, size_too_small,size_too_big, number.human.storage_units.units.mb)
- Put
require 'file_size_validator'
to my model - restart server etc...
There is nothing overlooked
but when I try to upload video with 24MB of size, i got the error :
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'
here's id.yml
looks like :
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"
here's 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
}
Here's videos_controller.rb
line 67
@video = Video.create(params[:video])
Could you please help me correct my steps and my code ?
Thanks