4

我正在尝试根据 rails docs 中所示的简单条件验证模型属性。我有一个带有布尔“show_birthday”属性的测验模型和一个带有生日属性的参与者模型。这是我的代码的相关部分:

class Participant < ActiveRecord::Base
    belongs_to :quiz
    validates :birthday, presence: true, :if => :has_birthday?

    def has_birthday?
        quiz.show_birthday?
    end
end

如果我删除 if 条件,验证有效,但即使我更改 has_birthday 中的部分也无效?方法为“真”。关于为什么这不起作用的任何想法?

4

0 回答 0