Skip to content
scambra edited this page Sep 14, 2010 · 21 revisions

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
  1. 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}_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
active_scaffold :user do |config|
config.columns[:open].search_ui = :status
end

end

module UsersHelper
def active_scaffold_search_status(record, input_name)
select :record, :status, options_for_select([‘open’, ‘closed’]), {:include_blank => as_(‘- select -’)}, :name => input_name
end
end

Clone this wiki locally