【发布时间】: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