DEV Community

bomoniyi
bomoniyi

Posted on

Using find_by instead of .where().first

Instead of

@the_movie = Movie.where(id: params.fetch(:id)).first
Enter fullscreen mode Exit fullscreen mode

Use

@the_movie = Movie.find_by(id: params.fetch(:id))
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
bomoniyi profile image
bomoniyi • Edited

You can use find() and an integer if you are searching only in the primary key column