parm530
11/6/2019 - 1:53 PM

`find_by`

Using find_by

  • Used to return 1 Active Record Object with multiple conditions rather than just by 1
    • Product.find_by(sku: "PARM-1", in_stock: true)
  • Will return nil if not found
    • Use find_by! with rescue to catch the error (since that will throw an ActiveRecord Error: NotFound)