为什么我会用pg_search获得无限循环?

时间:2013-03-26 11:46:57

标签: ruby-on-rails pg-search

当我将浏览器指向http://localhost:3000/searches时,我收到以下错误:

Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.

为什么呢?我该如何解决这个问题?

以下相关代码......

/config/routes.rb

resources :searches, :only => [:index]

/app/controllers/searches_controller.rb

class SearchesController < ApplicationController  
  respond_to :html
  filter_access_to :all
  def index
    @term = params[:term]
    @results = PgSearch.multisearch(@term) unless @term.blank?
    redirect_to searches_path
  end
end

/app/views/searches/index.html.haml

.textbox
  = render "shared/notice"
  %h1 Advanced Search
  = simple_form_for @searches do |f|
    = f.input :term
    = f.button :submit
  - unless @results.blank?
    - @results.each do |result|
      %h3= result.searchable.header
      %p= result.searchable.body

/config/authorization_rules.rb

authorization do
  role :admin do
    has_permission_on [...snip... :searches], :to => [:index, :show, :new, :create, :edit, :update, :destroy, :print, :none, :audit]     
  end
end

/app/models/reference.rb

class Reference < ActiveRecord::Base
  has_paper_trail
  include PgSearch
  multisearchable :against => [:source_text, :citation]
  attr_accessible :reference_ids, :question_ids
  attr_accessible :url, :citation, :details, :veracity_id, :original, :source_text
  has_many :footnotes
  def header
    self.citation
  end
  def body
    self.details
  end
end

/app/models/footnote.rb

class Footnote < ActiveRecord::Base
  has_paper_trail
  include PgSearch
  multisearchable :against => [:details]
  attr_accessible :reference_id, :details, :page_range, :relevant
  belongs_to :reference
  def header
    [self.reference.citation, " ", self.page_range].join
  end  
  def body
    self.details
  end
end

/db/migrate/20130326110126_create_pg_search_documents.rb

class CreatePgSearchDocuments < ActiveRecord::Migration
  def self.up
    say_with_time("Creating table for pg_search multisearch") do
      create_table :pg_search_documents do |t|
        t.text :content
        t.belongs_to :searchable, :polymorphic => true
        t.timestamps
      end
    end
  end
  def self.down
    say_with_time("Dropping table for pg_search multisearch") do
      drop_table :pg_search_documents
    end
  end
end

/db/migrate/20130326110723_rebuild_search_indexes.rb

class RebuildSearchIndexes < ActiveRecord::Migration
  def up
    PgSearch::Multisearch.rebuild(Reference)
    PgSearch::Multisearch.rebuild(Footnote)
  end
  def down
    PgSearch::Reference.delete_all
    PgSearch::Footnote.delete_all
  end
end

1 个答案:

答案 0 :(得分:0)

你有一个循环重定向; redirect_to searches_path只是将请求发回到同一个操作中。

尝试取出redirect_to行。这样Rails默认会呈现app/views/searches/index.html.haml。然后发布到表单应再次请求index并生成您想要的内容。