【问题标题】:Solr / Sunspot / Rails 3 error: undefined method `closed?' for nil:NilClassSolr / Sunspot / Rails 3 错误:未定义的方法“关闭?”对于零:NilClass
【发布时间】:2011-11-02 18:39:40
【问题描述】:

我有这个模型:

class Book < Item
  validates :isbn, :presence => true, :uniqueness => true

  has_many  :book_chapters
  has_many  :chapters,  :through => :book_chapters

  searchable :auto_index => true, :auto_remove => true do
      text :title
  end
end

然后我有了这个控制器:

class HomeController < ApplicationController
    def index

      @search = Book.search do
        fulltext params[:search]
      end
      @books = @search.results

      [... normal rest of code ...]
    end
end

字段“title”继承自更通用的 Item 模型。当 Home 控制器尝试执行搜索时,我收到此错误:

HomeController#index 中的 NoMethodError

未定义的方法“关闭?”对于 nil:NilClass

日志中还有这个额外的警告:

弃用警告:class_inheritable_attribute 已弃用,请改用 class_attribute 方法。请注意它们的行为略有不同,因此请先参阅 class_attribute 文档。 (从 /Users/xxx/Sites/zigzag/app/models/book.rb:7 调用)

指的是哪一行:

可搜索 :auto_index => true, :auto_remove => true 做

在 book.rb 中

知道为什么我会收到此错误吗?在堆栈溢出的其他类似帖子中,似乎人们忘记打开太阳黑子服务器。但我正在运行它,它运行良好。我可以很好地浏览 Solr Admin。谢谢!

【问题讨论】:

  • 看起来您并没有做错什么,最好将其作为 Sunspot 的错误报告。试试他们的邮件列表:groups.google.com/group/ruby-sunspot — 您还应该尝试获取更完整的堆栈跟踪 undefined method closed? 错误。最后,尝试在 git 中更新到最新的源代码,看看错误是否已经修复。

标签: ruby-on-rails-3 solr sunspot


【解决方案1】:

我想通了。我在 Mac OS Lion 10.7.2 上运行这个应用程序。问题是 rails 应用程序确实没有连接到 sunspot 服务器中。但原因并不是因为缺少太阳黑子服务器。这是因为 rails 使用的是 IPv4 地址,而 sunspot 需要的是 IPv6 地址。修复的第一部分是更改 sunspot.yml 配置文件,使主机名是 127.0.0.1 而不是“localhost”。然后,在 /etc/hosts 中,注释掉以下行:

#::1            localhost 
#fe80::1%lo0    localhost

所以'localhost' 只映射到 127.0.0.1(在 /etc/hosts/ 的其他地方指定)。就是这样!

【讨论】:

  • 全部打开终端,输入“cd /etc/hosts”
【解决方案2】:

一个简单的答案是你可能还没有开始你的太阳黑子 solr。尝试运行这个 rake 命令:

rake sunspot:solr:start

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 2016-06-05
    相关资源
    最近更新 更多