Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement