Class: CustomAttributes::IntFieldType

Inherits:
Numeric show all
Includes:
Singleton
Defined in:
lib/custom_attributes/field_types/int_field_type.rb

Instance Method Summary collapse

Methods inherited from FieldType

#after_save_custom_value, available_types, #before_custom_field_save, #cast_custom_value, #cast_value, #edit_tag, find, #name, #possible_custom_value_options, #possible_values_options, #set_custom_field_value, #validate_custom_field, #validate_custom_value, #value_from_keyword

Instance Method Details

#cast_single_value(custom_field, value, customized = nil) ⇒ Object



9
10
11
# File 'lib/custom_attributes/field_types/int_field_type.rb', line 9

def cast_single_value(custom_field, value, customized=nil)
  value.to_i
end

#labelObject



5
6
7
# File 'lib/custom_attributes/field_types/int_field_type.rb', line 5

def label
  "label_integer"
end

#validate_single_value(custom_field, value, customizable = nil) ⇒ Object



13
14
15
16
17
# File 'lib/custom_attributes/field_types/int_field_type.rb', line 13

def validate_single_value(custom_field, value, customizable = nil)
  errs = super
  errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless value.to_s =~ /^[+-]?\d+$/
  errs
end