Created
December 15, 2014 07:57
-
-
Save easonhan007/bb9645fbd0e74fa1aef4 to your computer and use it in GitHub Desktop.
tableless没有数据库table的model
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 characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment