See +CarrierWave::Mount#mount_uploader+ for documentation
# File lib/carrierwave/orm/activerecord.rb, line 12 def mount_uploader(column, uploader, options={}, &block) super alias_method :read_uploader, :read_attribute alias_method :write_uploader, :write_attribute validates_integrity_of column if uploader_option(column.to_sym, :validate_integrity) validates_processing_of column if uploader_option(column.to_sym, :validate_processing) after_save "store_#{column}!" before_save "write_#{column}_identifier" after_destroy "remove_#{column}!" end
Makes the record invalid if the file couldn’t be uploaded due to an integrity error
Accepts the usual parameters for validations in Rails (:if, :unless, etc…)
Set this key in your translations file for I18n:
carrierwave:
errors:
integrity: 'Here be an error message'
# File lib/carrierwave/orm/activerecord.rb, line 39 def validates_integrity_of(*attrs) options = attrs.last.is_a?(Hash) ? attrs.last : {} validates_each(*attrs) do |record, attr, value| if record.send("#{attr}_integrity_error") message = options[:message] || I18n.t('carrierwave.errors.integrity', :default => 'is not an allowed type of file.') record.errors.add attr, message end end end
Makes the record invalid if the file couldn’t be processed (assuming the process failed with a CarrierWave::ProcessingError)
Accepts the usual parameters for validations in Rails (:if, :unless, etc…)
Set this key in your translations file for I18n:
carrierwave:
errors:
processing: 'Here be an error message'
# File lib/carrierwave/orm/activerecord.rb, line 63 def validates_processing_of(*attrs) options = attrs.last.is_a?(Hash) ? attrs.last : {} validates_each(*attrs) do |record, attr, value| if record.send("#{attr}_processing_error") message = options[:message] || I18n.t('carrierwave.errors.processing', :default => 'failed to be processed.') record.errors.add attr, message end end end