开发者

In ActiveScaffold a Form Override breaks Field Search

开发者 https://www.devze.com 2022-12-08 12:36 出处:网络
In a Rails app I have Sales and Salespeople: class Sale < ActiveRecord::Base belongs_to :salesperson

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 correc开发者_Python百科tly 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


override the search field as described in https://github.com/activescaffold/active_scaffold/wiki/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
0

精彩评论

暂无评论...
验证码 换一张
取 消