cyberfly
12/4/2019 - 9:22 AM

Rails start date and end date range filter

scope :start_date, -> start_date { where("date >= ?", start_date) }

scope :end_date, -> end_date { where("date <= ?", end_date) }
class OrdersController < ApplicationController
  
  has_scope :code
  has_scope :start_date
  has_scope :end_date

  def index
    @orders = apply_scopes(Order)
    .page(params[:page])
    .per(get_per)
  end
end