title: ActiveAdmin custom filter from model attributes on the fly
body: <p>I am updating an old ruby\rails application that has an ActiveAdmin component (ActiveAdmin 0.6, Ruby 1.9.3 and Rails 3.2).  The user has requested a filter that searches all fields in a given model.  I don't think this is practical because you can't search a date or numeric value for "a" so I have compromised on just searching text with the filter.  </p>
  
  <p>Having looked at the ActiveAdmin documentation this states that you can create a filter for several attributes using "<em>or</em>" between the attributes.  So if I wanted to search the "circumstances" or "accident_type" attributes I would use the filter below:</p>
  
  <pre><code>filter :circumstances_or_accident_type, :as =&gt; :string, label: "Search All Text Fields"
  </code></pre>
  
  <p>If I use this syntax the filter works as expected.  </p>
  
  <p>I now want to find all the string\text attributes to create by filter attributes which I did using this code (there are probably neater ways of doing this but it works):</p>
  
  <pre><code>xfilter_text = ""
  Notification.columns.each do |xfield|
    if xfield.type == :string or xfield.type == :text
      if xfilter_text.length == 0
        xfilter_text = xfield.name
      else
        xfilter_text &lt;&lt; "_or_"
        xfilter_text &lt;&lt; xfield.name
      end
    end
  end
  </code></pre>
  
  <p>I used the result to hard-code the values into the filter which gave me the following (yes there are a few attributes in the model):</p>
  
  <pre><code>filter :circumstances_or_accident_type_or_author_type_or_location_or_immediate_action_or_injury_details_or_outcome_type_or_investigation_findings_or_action_to_prevent_recurrence_or_building_or_classification_or_manager_email_or_manager_name_or_current_stage_or_injured_last_name_or_injured_first_name_or_injured_gender_or_injured_address_or_injured_home_telephone_or_injured_work_status_or_injured_job_title_or_injured_working_pattern_or_injured_email_or_riddor_document_or_body_part_or_kind_of_accident_or_injury_type_or_service_or_team_or_defects_or_witness_details_or_location_details_or_hse_reference_number_or_riddor_category_or_address_or_details_of_treatment_or_processor_actions_or_business_unit_or_other_author_type_or_lost_time_details_or_changed_by_or_details_of_hospital_treatment, :as =&gt; :string, label: "Search All Text Fields"
  </code></pre>
  
  <p>I tested this and it worked.  All good so far.  I could just leave it here but I wanted to ensure the code is self maintaining so any changes in the model would not require changes to the custom filter.  This is the part I am having trouble with.  I would like to change the hardcoded attributes to use the results of the code that creates the filter attributes somehow.  Something like this:</p>
  
  <pre><code>filter :get_filter, :as =&gt; :string, label: "Search All Text Fields"
  
  def get_filter
    xfilter_text = ""
    Notification.columns.each do |xfield|
      if xfield.type == :string or xfield.type == :text
        if xfilter_text.length == 0
          xfilter_text = xfield.name
        else
          xfilter_text &lt;&lt; "_or_"
          xfilter_text &lt;&lt; xfield.name
        end
      end
      return xfilter
    end
  end
  </code></pre>
  
  <p>I expect that I would need something that checks that attributes are returned otherwise the filter would fail.  I can add that once I get the code working.  </p>
  
  <p>Appreciate any help or suggestions.  </p>