Class: Contact
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Contact
- Defined in:
- app/models/contact.rb
Class Method Summary collapse
- .search_by_department ⇒ Object
- .search_by_name(results, name) ⇒ Object
-
.search_by_params(results = nil, query) ⇒ Object
search <——————————————–.
Class Method Details
.search_by_department ⇒ Object
65 66 67 |
# File 'app/models/contact.rb', line 65 def self.search_by_department @contacts = @customer.contacts.where( @selected_department ? ({ department_id: @selected_department }) : "1=1") end |
.search_by_name(results, name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/contact.rb', line 43 def self.search_by_name(results, name) conditions = [] conditions_and = [] conditions_params = [] if name name = name.upcase conditions_and << 'upper(name) LIKE ?' conditions_params << "%#{name}%" end conditions << conditions_and.join(" and ") conditions_params.each { |p| conditions << p } if conditions.count>0 logger.debug results ret = results.where(conditions) else [] end end |
.search_by_params(results = nil, query) ⇒ Object
search <——————————————–
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/contact.rb', line 21 def self.search_by_params(results=nil, query) results = self.send(:relation) if results.nil? where = {} query.each do |k,v| next if v.nil? if k=="name" where.merge! 'upper(name) LIKE ?', "%#{name}%" elsif self.instance_methods.include?("#{k}_id".to_sym) where.merge! :"#{k}_id" => v elsif self.instance_methods.include?(k.to_sym) where.merge! k.to_sym => v end end results.where(where) end |