DEV Community

pbohea
pbohea

Posted on

1

find_by() & find()

find_by() returns a single instance, not an array.

Movie.find_by(id:3).title will return the title of the movie with id 3. if the id doesnt exist, it returns "nil".

find() also returns a single instance, but assumes you are searching for primary key (ID).
Movie.find(3).title returns the title of movie with id 3. if id doesnt exist, it returns 404 error.

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay