Solr / Sunspot / Rails 3 Error: undefined `closed? Method 'for nil: NilClass

I have this model:

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

And I have this controller:

class HomeController < ApplicationController
    def index

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

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

The "title" field is inherited from the more general Item model. And when the Home controller tries to search, I get this error:

NoMethodError in HomeController index #

undefined method `closed? 'for nil: NilClass

The log also has this additional warning:

DEPARTMENT WARNING: class_inheritable_attribute is deprecated, use the class_attribute method instead. Note that their behavior is slightly different, so check the class_attribute documentation first. (called from /Users/xxx/Sites/zigzag/app/models/book.rb:7)

What pertains to the line:

for search: auto_index => true ,: auto_remove => true do

in book.rb

, ? , . , . Solr Admin . !

+2
2

. Mac OS Lion 10.7.2. , rails sunspot. , . , IPv4, IPv6. sunspot.yml, 127.0.0.1, "localhost". /etc/hosts :

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

, "localhost" 127.0.0.1 ( /etc/hosts/ ). !

0

, , , solr. rake:

rake sunspot:solr:start
0

Source: https://habr.com/ru/post/1766705/


All Articles