"您需要提供至少一次验证"但Rails验证存在

时间:2014-09-20 22:48:44

标签: ruby-on-rails validation

我有以下验证:

class Event < ActiveRecord::Base
  attr_accessible :starts, :ends

  validates :no_multi_day_events

  private
    def no_multi_day_events
      if (ends.day != starts.day)
        errors.add(:ends, "No multi-day events")
      end
    end
end

但是,当我尝试使用此文本加载页面时,出现错误:You need to supply at least one validation

如何提供验证?

1 个答案:

答案 0 :(得分:19)

你应该打电话:

validate :no_multi_day_events

而不是

validates :no_multi_day_events