Method: ActiveScaffold::Finder::ClassMethods#condition_for_search_ui

Defined in:
lib/active_scaffold/finder.rb

#condition_for_search_ui(column, value, like_pattern, search_ui) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/active_scaffold/finder.rb', line 157

def condition_for_search_ui(column, value, like_pattern, search_ui)
  case search_ui
  when :boolean, :checkbox
    if value == 'null'
      condition_for_null_type(column, value)
    else
      ['%<search_sql>s = ?', column.column ? ActiveScaffold::Core.column_type_cast(value, column.column) : value]
    end
  when :integer, :decimal, :float
    condition_for_numeric(column, value)
  when :string, :range
    condition_for_range(column, value, like_pattern)
  when :date, :time, :datetime, :timestamp
    condition_for_datetime(column, value)
  when :select, :select_multiple, :draggable, :multi_select, :country, :usa_state, :chosen, :multi_chosen
    values = Array(value).select(&:present?)
    ['%<search_sql>s in (?)', values] if values.present?
  else
    if column.text?
      value = column.active_record? ? column.active_record_class.sanitize_sql_like(value) : value
      ["%<search_sql>s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
    else
      ['%<search_sql>s = ?', ActiveScaffold::Core.column_type_cast(value, column.column)]
    end
  end
end