Created
December 15, 2014 07:57
-
-
Save easonhan007/bb9645fbd0e74fa1aef4 to your computer and use it in GitHub Desktop.
Revisions
-
easonhan007 created this gist
Dec 15, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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