Skip to content

Instantly share code, notes, and snippets.

@easonhan007
Created December 15, 2014 07:57
Show Gist options
  • Select an option

  • Save easonhan007/bb9645fbd0e74fa1aef4 to your computer and use it in GitHub Desktop.

Select an option

Save easonhan007/bb9645fbd0e74fa1aef4 to your computer and use it in GitHub Desktop.

Revisions

  1. easonhan007 created this gist Dec 15, 2014.
    24 changes: 24 additions & 0 deletions stock_config.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    class StockConfig
    include ActiveModel::Validations
    include ActiveModel::Conversion
    extend ActiveModel::Naming
    include Virtus.model

    attribute :money, Integer
    attribute :month, Integer
    attribute :policy_id, Integer

    validates :money, :month, :policy_id, presence: true
    validates :money, numericality: { greater_than_or_equal_to: 3000, message: '必须大于3000' }
    validate :validates_money

    def persisted?
    false
    end

    # 金额必须是1000的倍数
    def validates_money
    errors.add(:money, '金额必须是1000的倍数') unless (money % 1000 == 0)
    end

    end #StockConfig