Rails 3 complicated validation design
我有一个
才有效
所以我有
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Class Contribution < ActiveRecord::Base attr_accessible :reward_id, :reward belongs_to :reward validates_presence_of :amount validates_numericality_of :amount, greater_than: 0 validates_presence_of :reward validates_each :amount, unless: SOMECONDITION do |contribution, attr, amount| reward = contribution.reward contribution.errors.add(attr, "Contribution must be at least #{reward.minimum_contribution}") unless amount > reward.minimum_contribution end end |
我的问题是什么适合放置
我应该在
您可以将
1 2 3 4 5 6 7 | ... validate :validate_mininum_amount def validate_mininum_amount errors.add :amount,"some error message" if amount.to_i < reward.min_contribution end ... |
注意:如果是