Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#conditions(model) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/application_controller.rb', line 4

def conditions(model)
  @conditions = []
   operators = [">", "<", "!"]

   params.each do |key,value|
     operator = nil
     if key =~ /^(.*?)(#{operators.join "|"})$/
       key = $1
       operator = $2
     end

     next if not model.columns.map(&:name).include? key # allow filtering only on indexed fields

     if operator
       @conditions << key.to_s + " " + operator + "='" + value.to_s + "'" 
     else
       @conditions << key.to_s + " " + "='" + value.to_s + "'" 
     end
     
   end
end