when i use where.take by greater than condition,rubocop advise i use find_by instead of them
C: Rails/FindBy: Use find_by instead of where.take.
total_miles = where(car_number: car_no).where('update_time >= ?', Time.current - 0.5.hours).take&.total_miles
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
$ rubocop -V
0.45.0 (using Parser 2.3.1.4, running on ruby 2.3.1 x86_64-linux)
Can you clarify how this is not good advice? The generated SQL should be the same. 馃榾
Finally, I adopted the writi like
total_miles = where('update_time >= ?', Time.current - 0.5.hours).find_by(car_number: car_no)&.total_miles
I think this is Rubocop meaning,thanks.
Most helpful comment
Finally, I adopted the writi like
I think this is Rubocop meaning,thanks.