【问题标题】:Rails 4.1 - thinking-sphinx association not workingRails 4.1 - 思考狮身人面像协会不起作用
【发布时间】:2014-07-21 13:38:31
【问题描述】:

我有一个包含两个模型的 Rails 应用程序,PostUser,我使用 Sphinxthinking-sphinx gem 来启用搜索。每个帖子属于一个用户,belongs_to,每个用户可以有多个帖子。当我搜索帖子时,我还希望能够按创建帖子的用户名进行搜索。我的帖子索引如下所示:

ThinkingSphinx::Index.define :post, :with => :active_record do
  indexes name, :sortable => true
  indexes post_description
  indexes user.name, as: :post_user

  has user_id, team_id, created_at, updated_at
end

我的用户索引如下所示:

ThinkingSphinx::Index.define :user, :with => :active_record do
  indexes name, :sortable => true
  indexes email
  indexes about

  has team_id, created_at, updated_at
end

当我运行:rake ts:index 时,我收到以下错误:

rake aborted!
NoMethodError: undefined method `_reflect_on_association' for #<Class:0x007fd417610c90>

关于如何解决它有什么想法吗?

更新

当我没有收到任何错误时,我很确定正是这一行导致了他 indexes user.name, as: :post_user。但是关联还是不行..

【问题讨论】:

    标签: ruby-on-rails ruby sphinx thinking-sphinx


    【解决方案1】:

    这是由于joiner gem(版本0.3.2)的更新,它需要Rails &gt;= 4.1.2

    查看此提交:https://github.com/pat/joiner/commit/de1403ec85d21dabf21a715ae962ee31c6ffe8d1

    更新到 Rails 4.1.2 或将以下内容添加到您的 Gemfile

    gem 'joiner', '0.3.1'
    

    【讨论】:

    • 你拯救了我的一天。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多