How can I drain my verification code? I have a Discussion model that has category and status fields. The status value depends on the category value. A discussion in which category == 'question' can only be STATUSES[:question] .
STATUSES = { question: %w[answered], suggestion: %w[pending planned started completed declined], problem: %w[started solved] } validates :status, allow_blank: true, inclusion: { in: STATUSES[:question] }, if: lambda { self.category == 'question' } validates :status, allow_blank: true, inclusion: { in: STATUSES[:suggestion] }, if: lambda { self.category == 'suggestion' } validates :status, allow_blank: true, inclusion: { in: STATUSES[:problem] }, if: lambda { self.category == 'problem' }
I am using Rails 3.
source share