我的模型有以下范围:
class Cloth < ActiveRecord::Base
include Ownerable
has_many :cloth_tags, :dependent => :destroy
pg_search_scope :full_search,
associated_against: {
cloth_tags: [:name, :brand_name]
},
against: [:name, :description],
ignoring: :accents,
using: {
tsearch: {
dictionary: "spanish",
any_word: true
}
}
因此,如果我调用类似的东西Cloth.full_search('shirt')
可以正常工作,但如果我添加owner: [:name]
到associated_against
哈希中,它会抛出NameError: uninitialized constant Cloth::Owner
. 不用说,正常情况下的所有者关系是有效的。无论如何在这样的模块中定义:
module Ownerable
extend ActiveSupport::Concern
included do
belongs_to :owner, :polymorphic => true
end
任何线索可能是什么?提前致谢