Вопрос

When I point my browser at http://localhost:3000/searches, I get the following error:

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

Why? And how do I fix this?

Relevant code below...

/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
Это было полезно?

Решение

You've got a cyclic redirect; redirect_to searches_path just sends the request back into the same action.

Try just taking the redirect_to line out. That way Rails will render app/views/searches/index.html.haml by default. Then posting to the form should request index again and produce what you want.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top