I have several records with several attributes (A, B, C, D).
I want to find which record has a higher value for a given attribute, for example D.
How to do it?
You can give max_by look.
objects = [some array of objects] object_with_highest_value = objects.max_by {|obj| obj.desired_value }
Depending on the number of records, you may have a more efficient search in the database. I would order the desired attribute in descending order and take the first entry:
User.order('field DESC').first
Source: https://habr.com/ru/post/899190/More articles:https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/899185/nscfdictionary-setobjectforkey-mutating-method-sent-to-immutable-object&usg=ALkJrhhLsi3b5hiJTz9QW-w44tvwNCRJcgiOS AVFoundation captureStillImageAsynchronouslyFromConnection: completeHandler: hanging endlessly - iosSICP sqrt NullPointerException - nullpointerexceptionHow to create a text index to search for% abc%? - sqlHackintosh iOS app development - can I let it go in the Apple app store? - iosonMeasure not getting a call in my regular android viewgroup - androidGet time from xts - rPhone camera crash when receiving data - androidAndroid - saving application state - androidNotification Window - Preventing window focus - c #All Articles