Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def self.note_search(params)
- matches = Coupon.all
- params.each do |key, val|
- case key
- when 'from'
- if val.present? && params[:to].present?
- from = Time.parse(params[:from]).beginning_of_day
- to = Time.parse(params[:to]).end_of_day
- matches.where!(created_at: from..to)
- end
- when 'promo_code'
- if val.present?
- val.split(' ').each do |t|
- t = "%#{t.downcase}%"
- matches.where!("lower(title) LIKE ? or lower(coupon) LIKE ?", t, t )
- end
- end
- end
- end
- matches
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement