use scope in rails 6 code example
Example: rails scopes
class Book < ApplicationRecord
scope :costs_more_than, ->(amount) { where("price > ?", amount) }
end
class Book < ApplicationRecord
scope :costs_more_than, ->(amount) { where("price > ?", amount) }
end