Class: Bureaucrat::Fields::FloatField

Inherits:
IntegerField show all
Defined in:
lib/bureaucrat/fields.rb

Instance Attribute Summary

Attributes inherited from Field

#error_messages, #help_text, #hidden_widget, #initial, #label, #required, #show_hidden_initial, #validators, #widget

Instance Method Summary collapse

Methods inherited from IntegerField

#initialize

Methods inherited from Field

#bound_data, #clean, #default_hidden_widget, #default_validators, #default_widget, #initialize, #initialize_copy, #populate_object, #prepare_value, #run_validators, #validate, #widget_attrs

Constructor Details

This class inherits a constructor from Bureaucrat::Fields::IntegerField

Instance Method Details

#default_error_messagesObject



255
256
257
# File 'lib/bureaucrat/fields.rb', line 255

def default_error_messages
  super.merge(invalid: 'Enter a number.')
end

#to_object(value) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
# File 'lib/bureaucrat/fields.rb', line 259

def to_object(value)
  if Validators.empty_value?(value)
    return nil
  end

  begin
    Utils.make_float(value.to_s)
  rescue ArgumentError
    raise ValidationError.new(error_messages[:invalid])
  end
end