我怎样才能干掉我的验证码?我有一个Discussion
具有 aacategory
和status
字段的模型。状态值取决于类别值。category == 'question'
例如,只能在 中具有状态的讨论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' }
我正在使用 Rails 3。