SHARE
TWEET

Untitled

a guest Jul 16th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def self.note_search(params)
  2.     matches = Coupon.all
  3.  
  4.     params.each do |key, val|
  5.  
  6.       case key
  7.         when 'from'
  8.           if val.present? && params[:to].present?
  9.             from = Time.parse(params[:from]).beginning_of_day
  10.             to = Time.parse(params[:to]).end_of_day
  11.             matches.where!(created_at: from..to)
  12.           end
  13.  
  14.         when 'promo_code'
  15.           if val.present?
  16.             val.split(' ').each do |t|
  17.               t = "%#{t.downcase}%"
  18.               matches.where!("lower(title) LIKE ? or lower(coupon) LIKE ?", t, t )
  19.             end
  20.           end
  21.  
  22.       end
  23.  
  24.     end
  25.     matches
  26.   end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top