public
Description:
Home | Edit | New

Search Overrides

If you want to customize the search form interface for a column, you can define a specially named method in your helper file. The format is #{column_name}_search_column. So, for example, to customize the :username column displayed on your search view of UsersController, you would add a :username_search_column method to your UsersHelper file. If you want the post to be handled by ActiveScaffold, you need to use the params[:search] namespace. With the helper override this is taken care of if you use the second argument: the input name. See the example below for more details.

Example:

module UsersHelper
  # display the "status" field as a dropdown with open and closed options
  def status_search_column(record, input_name)
    select :record, :status, options_for_select(['open', 'closed']), {:include_blank => as_('- select -')}, :name => input_name
  end
end

Also you can customize conditions for a seach_ui or type column, adding a class method to the controller named condition_for_#{search_ui}_type, or conditions for a specific column adding a class method to the controller named condition_for_#{column_name}_column. That method should return a conditions array.

Example:

class UsersController < ApplicationController
  def self.condition_for_status_column(column, value, like_pattern)
    case value
      when 'open'
        ["#{column.search_sql} IS NOT NULL"]
      when 'closed'
        ["#{column.search_sql} IS NULL"]
    end
  end
Last edited by scambra, Wed Sep 23 07:07:30 -0700 2009
Home | Edit | New
Versions: