You are here: Browse Railsplugins Active Scaffold List Filters
Copyright© 2008 Tys von Gaza (tys@gotoybox.com)
MIT License use as you wish, see MIT-LICENSE file
Version 0.5
Add a filter menu at the top of the ActiveScaffold List view. The filter can be whatever you dream up. Code inspiration: activescaffoldexport plugin.
class ApplicationController < ActionController::Base ActiveScaffold.set_defaults do |config| config.actions.add :list_filter end end
or an individual controller
active_scaffold "Model" do |config|
config.actions.add :list_filter
end
active_scaffold “Model” do |config| config.list_filter.add(:association, :district, {:label => “Districts”) end
Add an Association (checkboxes) filter, named city, with the label Cities, but using the association named town:
active_scaffold "Model" do |config|
config.list_filter.add(:association, :city, {:label => "Cities", :association => :town)
end
It is simple to create your own filter.
list_filter_input_name(filter)[]
class ListFilters::Association < ActiveScaffold::DataStructures::ListFilter
def find_options begin assocation = @core.model.reflect_on_association(assocation_name) options = {} options[:include] = assocation_name options[:conditions] = [”#{assocation.klass.table_name}.id IN (?)”, params] end
return options
end unless params.nil? || params.empty?def verbose begin ar_class = association_tree.last.class_name.constantize associated_values = ar_class.find(params).sort {|a,b| a.to_label <=> b.to_label } verbose_values = associated_values.collect{|av| av.to_label}.join(”, “) return verbose_values end unless params.nil? || params.empty? end
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly