views:

193

answers:

1

In a Rails app I have Sales and Salespeople:

class Sale < ActiveRecord::Base
  belongs_to :salesperson
end

class Salesperson < ActiveRecord::Base
  has_many :sales
end

I have an ActiveScaffold for sales. I've switched on field searching and can successfully filter my sales by salesperson. However I only want to show a subset of salepeople in the salesperson drop-down so I am using a form override:

def salesperson_form_column(record, input_name)
  select :record, :salesperson, current_user.office.salespeople.find(:all).collect {|p| [ p.name, p.id ] }, :name => input_name
end

This works correctly on the form to create/update sales records, however it doesn't work on the field searching. The drop-down correctly appears, but doesn't have any effect. I can pick a saleperson but the list doesn't filter.

I compared the generated HTML between the standard saleperson drop-down and my overrideen one and they do seem to differ slightly:

<select class="salesperson-input" id="search_salesperson" name="search[salesperson][id]">

-vs-

<select class="" id="record_salesperson" name="search [salesperson]">

Any ideas? Thanks

+1  A: 

override the search field as described in http://wiki.github.com/activescaffold/active%5Fscaffold/search-overrides.

def salesperson_search_column(record, input_name)
    select :record, :salesperson, current_user.office.salespeople.find(:all).collect {|p| [ p.name, p.id ] }, :name => input_name
end
anithri