在 ActiveScaffold 中,表单覆盖会破坏字段搜索

发布于 2024-08-08 20:21:40 字数 884 浏览 5 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮烟 2024-08-15 20:21:40

覆盖搜索字段,如 https://github.com/activescaffold/active_scaffold/wiki 中所述/搜索覆盖

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文