我有这个模型:
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
然后我有这个 Controller :
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 Controller 尝试执行搜索时,我收到此错误:
NoMethodError in HomeController#index
undefined method `closed?' for nil:NilClass
日志中还有这个额外的警告:
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from /Users/xxx/Sites/zigzag/app/models/book.rb:7)
其中指的是行:
searchable :auto_index => true, :auto_remove => true do
在 book.rb 中
知道我为什么会收到此错误吗?在 stack overflow 的其他类似帖子中,人们似乎忘记打开 sunspot 服务器。但我正在运行它,并且运行良好。我可以很好地浏览 Solr Admin。谢谢!
最佳答案
我想通了。我在 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/中的其他地方指定)。就是这样!
关于ruby-on-rails-3 - Solr/太阳黑子/Rails 3 错误 : undefined method `closed?' for nil:NilClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7985617/
相关文章:
sql-server - 'Insert into linked table failed, RAI
wpf - 从 DataTemplate 中的控件获取 GridViewColumn
drupal - 在 drupal 7 中将表单元素添加到节点以供用户输入
Ruby Gem 安装失败 - 执行 gem 时出错 - 未初始化的常量 Syck::Syck
hibernate - 在 Java 构建路径中添加 jar 之前,无法通过在 pom.xml 中添
validation - 如何验证电子商务网站的电子邮件地址?