Module: ActiveRecord::DatabaseValidations::StringTruncator::ClassMethods
- Defined in:
- lib/active_record/validations/string_truncator.rb
Instance Method Summary collapse
Instance Method Details
#truncate_string(field) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/active_record/validations/string_truncator.rb', line 34 def truncate_string(field) method_name = :"truncate_#{field}_at_database_limit" define_method(method_name) do return unless self.changes.key?(field.to_s) self[field] = truncate_value_to_field_limit(field, self[field]) return # to make sure the callback chain doesn't halt end return method_name end |
#truncate_to_field_limit(field) ⇒ Object
28 29 30 31 32 |
# File 'lib/active_record/validations/string_truncator.rb', line 28 def truncate_to_field_limit(field) define_method(:"#{field}=") do |value| super(truncate_value_to_field_limit(field, value)) end end |