Class: LookingForController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/looking_for_controller.rb

Instance Method Summary collapse

Instance Method Details

#searchObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/looking_for_controller.rb', line 2

def search    
  object_eval = eval("#{params[:object_name]}") 
  if params[:looking_for_filter]
    params[:looking_for_filter].each do |key, value|
      if value!=""
        table_alias_and_field = key          
        table_alias_and_field = "#{params[:object_name].underscore}.#{key}" if key.split('.').length == 1
        ar = table_alias_and_field.split('.')  
        table_alias = ar[ar.length-2]
        field       = ar[ar.length-1]
        table_alias = table_alias.pluralize
        table_alias_and_field = "#{table_alias}.#{field}"
        
        if params[:no_case] && params[:no_case].include?(key)
          object_eval = object_eval.where("upper(#{table_alias_and_field}) like ? ",value.upcase+"%")
        elsif params[:use_upper] && params[:use_upper].include?(key)  
          object_eval = object_eval.where("#{table_alias_and_field} like ? ",value.upcase+"%")
        else
          object_eval = object_eval.where("#{table_alias_and_field} like ? ",value+"%")            
        end  
      end
    end  
  end  
  
  if params[:conditions] && params[:conditions].class == Array
    params[:conditions].collect! do |a|        
      if a=='true'
        true
      elsif a=='false'
        false
      else
        a
      end  
    end        
  end
  
  object_eval = object_eval.where(params[:conditions])if params[:conditions]    
  object_eval = object_eval.includes(params[:include]) if params[:include]
  
  @records = object_eval.paginate(:per_page => 10,:page => params[:page]).order(params[:order])
 
  template = 'looking_for' 
  template = 'assign_first' if @records.length == 1 && params[:validate] == 'true'
  template = 'clear' if params[:clear] == 'true'
 
  respond_to do |format|      
    format.js { render template}
  end
end