开发者

undefined method `closed?' for nil:NilClass Ruby on Rails Sunspot

开发者 https://www.devze.com 2023-04-05 07:22 出处:网络
I have spent more than 24 hours trying to figure out what im doing wrong here. Can you please help. This is what i have.

I have spent more than 24 hours trying to figure out what im doing wrong here. Can you please help. This is what i have.

lyrics_Controller.rb

def index
   @search = Sunspot.search(Lyric) do
    fulltext params[:search]
  end
  @lyrics = @search.results

    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json => @lyrics }
    end
  end

lyrics.rb (model)

class Lyric < ActiveRecord::Base
  has_many :styles
  belongs_to :artist

   extend FriendlyId
   friendly_id :name, :use => :slugged


searchable do
  text :name, :body
end
end

in my view i have a search form like so.

<%= form_tag lyrics_path, :method => :get do %>
                      <p>
                        <%= text_field_tag :search, params[:search] %>
                        <%= submit_tag "Search", :name => nil %>
                      </p>
<% end %>

When i try to search i get an error

NoMethodError in LyricsController#index undefined method `closed?' for nil:NilClass Rails.root: /Users/sigidis/Ruby/stagesong

Application Tr开发者_运维技巧ace | Framework Trace | Full Trace app/controllers/lyrics_controller.rb:10:in `index'

This is the log.

Started GET "/lyrics?utf8=%E2%9C%93&search=Soweto" for 127.0.0.1 at Sat Sep 17 11:37:04 +0200 2011 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/sigidis/Ruby/stagesong/app/models/lyric.rb:10) 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/sigidis/Ruby/stagesong/app/models/lyric.rb:10) Processing by LyricsController#index as HTML Parameters: {"utf8"=>"\342\234\223", "search"=>"Soweto"} Completed 500 Internal Server Error in 2ms

NoMethodError (undefined method closed?' for nil:NilClass): app/controllers/lyrics_controller.rb:10:inindex'

Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.9ms) Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.7ms) Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (3.1ms)

I am not sure what i am doing wrong. Can someone please help.

Also tried this

http://collectiveidea.com/blog/archives/2011/03/08/full-text-searching-with-solr-and-sunspot/

and this http://railscasts.com/episodes/278-search-with-sunspot


I had forgotten to start the sunsport gem.

0

精彩评论

暂无评论...
验证码 换一张
取 消