You have a webshop and you want to display all products that are on sale.
Let’s asume your products table has a column named sale and is of the type boolean.

In the product model you set the scope like this:

class Product < ApplicationRecord
  scope :on_sale, -> { where(sale: true) }

Now in the desired controller#action you can set the products that are on sale like this:

class ProductsController < ApplicationController
  def products_on_sale
    @products = Product.on_sale

Check out the Rails docs for more info about scopes.