Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用太阳黑子Solr Rails 3搜索多个模型时出错_Ruby On Rails_Ruby On Rails 3_Solr_Sunspot - Fatal编程技术网

Ruby on rails 使用太阳黑子Solr Rails 3搜索多个模型时出错

Ruby on rails 使用太阳黑子Solr Rails 3搜索多个模型时出错,ruby-on-rails,ruby-on-rails-3,solr,sunspot,Ruby On Rails,Ruby On Rails 3,Solr,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/

最终在搜索单个模型时太阳黑子可以工作,但在搜索多个模型时遇到了一些问题

我在搜索后遇到的错误:

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
搜索\u 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 documentals_controller.rb中的文章模型为例

它将在相同的文章索引页中呈现结果

因为,现在您已经创建了一个公共搜索控制器,所以需要在“视图”>“搜索”>“index.html.erb”中为该索引操作创建一个单独的视图,并在该页面中显示结果,或者渲染现有模板(如果可以使用render:=>您的_视图)

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