need help with a strategy for a custom field search.

17 views
Skip to first unread message

anithri

unread,
Dec 8, 2011, 5:15:05 PM12/8/11
to actives...@googlegroups.com
class Project
  has_many :events, :class_name => "EventLog"
end

class EventLog
  #attributes: event_type, event_date
end

I want to setup a field search column for Project that gives me a select list for Event Type as well as the normal date search fields.

I'd like to be able to use #active_scaffold_search_date_bridge to setup the date search form parts, and #condition_for_date_bridge_type (both in lib/active_scaffold/bridges/shared/date_bridge.rb) so I don't have to recreate them.  But I need to be able to add an event_type select that allows the user to choose the type of event to search for.  The tricky parts (as I see them) are 1.  ensuring that the search form state is saved and the existing selected values can be used to populate the search form again.  2.  ensuring that I don't repeat the code for setting up the form element or the conditions output.  3.  Doing it in a helper instead of editing the active_scaffold code directly.

I accept this is prolly not a safe way to do things, but I'm willing to accept some brittleness in order to get it working.

even a pointer to a code sample for a similar problem would be welcome.

Thanks.

Sergio Cambra

unread,
Dec 12, 2011, 11:31:17 AM12/12/11
to actives...@googlegroups.com

You should add event_type and event_date to your field_search columns:
conf.columns << [:event_date, :event_type] # define columns
conf.columns.exclude :event_date, :event_type # exclude from all actions
conf.field_search.columns << [:event_date, :event_type]

Then, you must set search_sql and search_ui for both columns. You can use
:select search_ui for event_type and set the options, if options can change in
each request use a before filter to set the available options.

Reply all
Reply to author
Forward
0 new messages