如果方法#2 == 0,则before_save方法#1?

时间:2016-03-09 01:03:07

标签: ruby-on-rails ruby methods model callback

如果用户追溯性地创建了质询,那么他已accomplished before_save如何days_left_challenged == 0

challenge.rb

  before_save :days_left_challenged_sets_deadline

  def days_left_challenged_sets_deadline
    if self.days_left_challenged == 0
      self.accomplished = true
    end
  end

  def days_left_challenged
    self.days_challenged - ((date_started.to_date)..Date.yesterday).count do |date| 
      committed_wdays.include? date.wday
    end + self.missed_days
  end

即使用户创建了具有accomplished的质询,立即使用此代码nil仍为days_left_challenged == 0

1 个答案:

答案 0 :(得分:0)

它必须是days_left_challenged <= 0因为我没有意识到它并没有停留在0. Rookie的错误。