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.

http://api.rubyonrails.org/classes/object.html#method-i-try


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -