Rails: Active Record find vs find_by(:id => id)

When I encountered ModelName.find_by(:id => model_id) I thought why would we do that? Doesn’t ModelName.find do the same thing.

So, like any good Rails developer, I did NOT refer to the documentation instead I tested it in rails console and found they are mostly the same with couple exceptions.


`find(one_or_array_of_ids)` will throw a RecordNotFoundException if the single id or any one of the ids in an array param are not found.

`find_by(:id => one_or_array_of_ids)` will return not throw an exception.


`find(one_or_array_of_ids)` will return an array of objects when an array of ids is given and all of them are present.

`find_by(:id => one_or_array_of_ids)` will only return one object with tthe highest id in the array. If none are found it will nil.

Rails version used: