if shift
カスタムバリデーターをチェックインする必要がありますか?validates :shift, presence: true
どうにかしてリファクタリングできますか?
class ShiftLog < ActiveRecord::Base
belongs_to :shift
validates :shift, presence: true
validate :check_limit
def check_limit
if shift
shift_logs = ShiftLog.by_shift(shift)
if shift_logs.count >= self.shift.limit
errors.add(:shift_id, "Exceeded limit")
end
end
end
end