【问题标题】:Thinking Sphinx - undefined method `klass'思考狮身人面像 - 未定义的方法`klass'
【发布时间】:2015-07-18 05:32:42
【问题描述】:

我有一个 Artwork 模型,它与 HABTM 的模型 SubjectLocationKeywordStyleMedium 相关联。我还与一对多的Artist 模型建立了关联。这是我不断收到的错误:

>rake ts:index
Generating configuration to /Users/<user>/Developer/jtodd/jtoddgalleries/config/development.sphinx.conf
rake aborted!
NoMethodError: undefined method `klass' for nil:NilClass

这是我的索引文件:

ThinkingSphinx::Index.define :artwork, :with => :active_record do
    indexes title, :sortable => true
    has jtg
    has width
    has height


    has subject.id, :as => :subject_ids
    has location.id, :as => :location_ids
    has keyword.id, :as => :keyword_ids
    has artist.first_name, :as => :artist_first
    has artist.last_name, :as => :artist_last

    has style.id, :as => :style_ids
    has medium.id, :as => :medium_ids
end

我不明白为什么我不断收到不同的错误。我可能对字段与属性没有牢牢把握,也许这就是我出错的地方。非常感谢任何帮助,谢谢!

【问题讨论】:

    标签: ruby-on-rails indexing associations rake thinking-sphinx


    【解决方案1】:

    我假设您的关联都以复数名称列在您的 Artwork 模型中?它需要在您的索引定义中相同。

    对于字段与属性,一个好的经验法则是,您希望用户输入并获得结果的任何内容都应该是字段。所以,我猜你会想要艺术家的名字和姓氏作为字段。

    因此,修改后的索引定义:

    ThinkingSphinx::Index.define :artwork, :with => :active_record do
      indexes title, :sortable => true
      indexes artist.first_name, :as => :artist_first
      indexes artist.last_name,  :as => :artist_last
      has jtg
      has width
      has height
    
      has subjects.id, :as => :subject_ids
      has locations.id, :as => :location_ids
      has keywords.id, :as => :keyword_ids
      has styles.id, :as => :style_ids
      has mediums.id, :as => :medium_ids
      # or is it media?
    end
    

    如果您仍然收到错误,您可以运行rake ts:index --trace 并与我们分享回溯吗? :)

    【讨论】:

    • 想通了,但这正是问题所在,谢谢您的确认!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多