【发布时间】:2012-04-05 03:14:06
【问题描述】:
我有两个模型。一个是品牌,另一个是product_detail。 Brands 表有 id 和 name 字段,product_details 表有 id、name、price、discount 和 brand_id 字段。
brand有很多product_details,product_detail属于brand
brand.rb 看起来像:
class Brand < ActiveRecord::Base
has_many :product_details
end
product_details.rb 看起来像
class ProductDetail < ActiveRecord::Base
belongs_to :Brand, :dependent=>:destroy
end
我正在尝试使用太阳黑子轨道进行搜索。我想使用用户输入的文本根据品牌名称和产品名称进行搜索。为此,我编写了这样的可搜索方法:
class ProductDetail < ActiveRecord::Base
belongs_to :brands, :dependent=>:destroy
searchable do
text :name
text :brands do
brands.map(&:name)
end
end
end
当我运行 rake sunspot:reindex
它为 nil 类抛出一个错误未定义的方法映射
如果像这样更改代码
class ProductDetail < ActiveRecord::Base
belongs_to :Brand, :dependent=>:destroy
searchable do
text :name
text :Brand do
brands.map(&:name)
end
end
end
它为 product_detail 类抛出一个错误 undefined methodbrands
请帮助我如何做到这一点。
【问题讨论】:
标签: ruby-on-rails-3 full-text-search sunspot sunspot-rails sunspot-solr