【发布时间】:2015-05-15 13:56:41
【问题描述】:
所以,我已经搞砸了好几个小时,我想我已经尝试了关于这个问题的所有内容。这是我的第一个问题。
所以,我正在尝试搜索模型(位置):branch_name、:branch_address1 等,并将其子模型(员工):first_name 在该模型中用作其自己的属性。因此,如果位置员工姓名在搜索查询中,则所需的效果将是位置(作为结果)将返回。我试图用这样的代码来实现这一点:
class Location < ActiveRecord::Base
belongs_to :partner
has_many :employees, dependent: :destroy
validates_presence_of :branch_name, :branch_address1, :branch_country, :branch_zip_code
accepts_nested_attributes_for :employees, allow_destroy: true, :reject_if > proc { |attributes| attributes['first_name'].blank? }
searchable do
text :branch_name, :branch_address1, :branch_city, :branch_zip_code
text :employee_attributes do
:first_name
if :employee_attributes
end
end
end
end
我也想使用父模型(合作伙伴)名称,但是我也无法让它工作。
我是否可以在 Locations 表中创建一个新列来捕获每个新员工的姓名,或者我可以在该模型子项中进行搜索吗?
【问题讨论】:
标签: ruby-on-rails postgresql ruby-on-rails-4 nested-attributes sunspot-rails