before_save if attribute.present?

Viewed 4053
before_save :date_started_sets_deadline, if date_started.present?

I don't want this before_save to run if :date_started == nil. I've tried various versions of the above line so not sure if I have to change that or the method itself.

def date_started_sets_deadline
  if self.date_started > Date.tomorrow
    self.deadline = self.date_started
  end
end

I'm trying to avoid the error NoMethodError (undefined method '>' for nil:NilClass): app/models/challenge.rb:35:in 'date_started_sets_deadline' whenever a user tries to create a challenge without a date_started

4 Answers
Related