【发布时间】:2016-03-13 01:34:44
【问题描述】:
我正在努力做到这一点,以便在任何给定时间只能填充三列中的一列。
这是我想到的一些伪代码:
class Model < ActiveRecord::Base
validates :column_one, presence: true,
absence: true if (:column_two.present? || :column_three.present?)
validates :column_two, presence: true,
absence: true if (:column_one.present? || :column_three.present?)
validates :column_three, presence: true,
absence: true if (:column_one.present? || :column_two.present?)
end
是否可以在模型级别执行此操作,还是我必须在控制器或参数中进行管理?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 rails-activerecord