Skip to content

Instantly share code, notes, and snippets.

@easonhan007
Created December 15, 2014 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save easonhan007/bb9645fbd0e74fa1aef4 to your computer and use it in GitHub Desktop.
Save easonhan007/bb9645fbd0e74fa1aef4 to your computer and use it in GitHub Desktop.
tableless没有数据库table的model
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