Sha256: a27dda5f85af248068ac339549d860c60f36aab87f9085485e688793d9b9e078

Contents?: true

Size: 451 Bytes

Versions: 6

Compression:

Stored size: 451 Bytes

Contents

module Cardboard
  class Field::Integer < Field
    validate :is_integer
    validate :is_required


    def value=(val)
      self.value_uid = val == "" ? nil : val #bug in rails? should work with allow_blank
    end

    def value
      self.value_uid.to_i
    end

    def default
      12321454
    end

  private

    def is_integer
      errors.add(:value, "is not a number") if value_uid.present? && value_uid.to_s =~ /[^\d]/
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cardboard_cms-0.3.1 app/models/cardboard/field/integer.rb
cardboard_cms-0.2.2 app/models/cardboard/field/integer.rb
cardboard_cms-0.2.1 app/models/cardboard/field/integer.rb
cardboard_cms-0.1.8 app/models/cardboard/field/integer.rb
cardboard_cms-0.1.6 app/models/cardboard/field/integer.rb
cardboard_cms-0.1.4 app/models/cardboard/field/integer.rb