我花了超过 24 小时试图弄清楚我在这里做错了什么。你能帮忙吗?这就是我所拥有的。
歌词控制器.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
歌词.rb(模型)
class Lyric < ActiveRecord::Base
has_many :styles
belongs_to :artist
extend FriendlyId
friendly_id :name, :use => :slugged
searchable do
text :name, :body
end
end
在我看来,我有一个像这样的搜索表单。
<%= form_tag lyrics_path, :method => :get do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
当我尝试搜索时出现错误
LyricsController#index 中的 NoMethodError 未定义方法“已关闭?” 对于 nil:NilClass Rails.root: /Users/sigidis/Ruby/stagesong
应用程序跟踪 | 框架跟踪 | 完整跟踪 app/controllers/lyrics_controller.rb:10:in `index'
这是日志。
开始 GET "/lyrics?utf8=%E2%9C%93&search=Soweto" for 127.0.0.1 at Sat Sep 17 11:37:04 +0200 2011 弃用警告:class_inheritable_attribute 已弃用,请改用 class_attribute 方法。请注意它们的行为略有不同,因此请先参阅 class_attribute 文档。(从 /Users/sigidis/Ruby/stagesong/app/models/lyric.rb:10 调用) 弃用警告:不推荐使用 class_inheritable_attribute,请改用 class_attribute 方法。请注意它们的行为略有不同,因此请先参阅 class_attribute 文档。(从 /Users/sigidis/Ruby/stagesong/app/models/lyric.rb:10 调用)由 LyricsController#index 处理为 HTML 参数:{"utf8"=>"\342\234\223", "search"= >“Soweto”} 在 2 毫秒内完成 500 内部服务器错误
NoMethodError(未定义的方法closed?' for nil:NilClass):
app/controllers/lyrics_controller.rb:10:in
索引'
渲染 /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.9ms) 渲染 /Library/Ruby/Gems/1.8/gems/actionpack-3.1 .0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.7ms) 渲染 /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics。救援/布局中的 erb (3.1ms)
我不确定我做错了什么。有人可以帮忙吗。
也试过这个
http://collectiveidea.com/blog/archives/2011/03/08/full-text-searching-with-solr-and-sunspot/