lib/active_scaffold/finder.rb
# Generates an SQL condition for the given ActiveScaffold column based on
# that column's database type (or form_ui ... for virtual columns?).
# TODO: this should reside on the column, not the controller
Generates an SQL condition for the given ActiveScaffold column based on
that column's database type (or form_ui ... for virtual columns?).
TODO: this should reside on the column, not the controller
Generates an SQL condition for the given ActiveScaffold column based on that column ' s database type ( or form_ui ... for virtual columns? ) . TODO : this should reside on the column not the controller
def condition_for_column(column, value, text_search = :full)
        like_pattern = like_pattern(text_search)
        value = value.with_indifferent_access if value.is_a? Hash
        if respond_to?("condition_for_#{column.name}_column")
          return send("condition_for_#{column.name}_column", column, value, like_pattern)
        end
        return unless column&.search_sql && value.present?
        search_ui = column.search_ui || column.column_type
        begin
          sql, *values =
            if search_ui && respond_to?("condition_for_#{search_ui}_type")
              send("condition_for_#{search_ui}_type", column, value, like_pattern)
            elsif column.search_sql.instance_of? Proc
              column.search_sql.call(value)
            else
              condition_for_search_ui(column, value, like_pattern, search_ui)
            end
          return nil unless sql
          conditions = [column.search_sql.collect { |search_sql| sql % {:search_sql => search_sql} }.join(' OR ')]
          conditions += values * column.search_sql.size if values.present?
          conditions
        rescue StandardError => e
          Rails.logger.error "#{e.class.name}: #{e.message} -- on the ActiveScaffold column :#{column.name}, search_ui = #{search_ui} in #{name}"
          raise e
        end
      end
def condition_for_column ( column , value , text_search = :full ) like_pattern = like_pattern ( text_search ) value = value . with_indifferent_access if value . is_a? Hash if respond_to? ( "condition_for_#{column.name}_column" ) return send ( "condition_for_#{column.name}_column" , column , value , like_pattern ) end return unless column &. search_sql && value . present? search_ui = column . search_ui || column . column_type begin sql , * values = if search_ui && respond_to? ( "condition_for_#{search_ui}_type" ) send ( "condition_for_#{search_ui}_type" , column , value , like_pattern ) elsif column . search_sql . instance_of? Proc column . search_sql . call ( value ) else condition_for_search_ui ( column , value , like_pattern , search_ui ) end return nil unless sql conditions = [ column . search_sql . collect { | search_sql | sql % { :search_sql => search_sql } } . join ( ' OR ' ) ] conditions += values * column . search_sql . size if values . present? conditions rescue StandardError => e Rails . logger . error "#{e.class.name}: #{e.message} -- on the ActiveScaffold column :#{column.name}, search_ui = #{search_ui} in #{name}" raise e end end
Generates an SQL condition for the given ActiveScaffold column based on
that column's database type (or form_ui ... for virtual columns?).
Generates an SQL condition for the given ActiveScaffold column based on that column ' s database type ( or form_ui ... for virtual columns? ) .
column
<not_specific>
value
<not_specific>
text_search
<not_specific>