簡體   English   中英

使用Sunspot Solr Rails 3搜索多個模型時出錯

[英]Error searching multiple models with Sunspot Solr Rails 3

最終使Sunspot在搜索單個模型時可以工作,但是在搜索多個模型時遇到了一些問題。

搜索后出現的錯誤:

Missing template search/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/Users/Indokathan/code/iibfy/app/views" * "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/devise-3.4.1/app/views"

search.rb

class Search < ActiveRecord::Base
 attr_accessible :title

 searchable do
   text :title      
  end
end

search_controller.rb

class SearchController < ApplicationController

def index
@search = Sunspot.search [Dairy, Drink] do
  fulltext params[:search]
 end
  @results = @search.results
 end  
end

searchbar.html.erb

<%= form_tag search_index_path, :method => :get do %>
<p>
    <%= text_field_tag :search, params[:search], style:"width:550px; height:30px;" %><br>
    <%= submit_tag "Search!", :name => nil, class: "btn btn-primary btn-lg", style: "margin-top:10px" %>
</p>

對於為什么我收到此錯誤的任何幫助將不勝感激。 如果您需要更多信息,請告訴我。

在進行單模型搜索時,您將結果呈現在受關注控制器的同一索引頁中,例如,讓我們采用與gem文檔( articles_controller.rb )中的Article模型相同的結果。

def index
  @search = Article.search do
      fulltext params[:search]
      with(:published_at).less_than(Time.zone.now)
    facet(:publish_month)
    with(:publish_month, params[:month]) if params[:month].present?
  end
  @articles = @search.results
end

它將在同一文章索引頁面中呈現結果。

由於現在您已經創建了一個通用的搜索控制器,因此需要在views>search>index.html.erb為此index操作創建一個單獨的視圖,並在該頁面中顯示結果或渲染現有模板(如果可以使用) render :=> "your_view"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM