在 ActiveScaffold 中,表单覆盖会破坏字段搜索
在 Rails 应用程序中,我有销售人员和销售人员:
class Sale < ActiveRecord::Base
belongs_to :salesperson
end
class Salesperson < ActiveRecord::Base
has_many :sales
end
我有一个用于销售的 ActiveScaffold。我已打开字段搜索,并且可以按销售人员成功过滤我的销售。但是,我只想在销售人员下拉列表中显示销售人员的子集,因此我使用表单覆盖:
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
这可以在表单上正常工作以创建/更新销售记录,但它不适用于字段搜索。下拉菜单正确显示,但没有任何效果。我可以选择一名销售人员,但该列表不会过滤。
我比较了标准销售员下拉列表和我的覆盖下拉列表之间生成的 HTML,它们似乎确实略有不同:
<select class="salesperson-input" id="search_salesperson" name="search[salesperson][id]">
-vs-
<select class="" id="record_salesperson" name="search [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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
覆盖搜索字段,如 https://github.com/activescaffold/active_scaffold/wiki 中所述/搜索覆盖
override the search field as described in https://github.com/activescaffold/active_scaffold/wiki/search-overrides