ruby on rails - Only update records that haven't been updated -
when creating record know can use method
.first_or_create!
to create records don't exist in model. need same when updating model. have app runs rake task apply score column in model.
prediction.update_attributes!(score: score)
i want update scores have not been updated yet.
is possible?
thanks
i think might looking try
method attempt call method on object potentially nil
.
example:
>> prediction.try(:update_attributes!, :score => some_new_score)
if prediction
nil
return nil
, not throw nomethoderror
. if prediction
object representing existing record, call method on object , update score
attribute.
Comments
Post a Comment