0

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
steven_noble
  • 4,133
  • 10
  • 44
  • 77
  • Looks like a cyclic redirect. Doesn't `redirect_to searches_path` just send the request back into the same action? – Chowlett Mar 26 '13 at 11:55
  • I thought it sent me back to /app/views/searches.html.haml. I was planning to use this page to both show search results and to collect search terms. But do I have to somehow break the process into two actions? – steven_noble Mar 26 '13 at 11:59
  • 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. – Chowlett Mar 26 '13 at 12:17
  • Thanks. That killed the loop. Now trying to work out the correct syntax for the `= simple_form_for @search do |f|` line. (As @search does not exist.) – steven_noble Mar 26 '13 at 12:23
  • Great. I'll post it as an answer. If you need help with the `@search` bit, I'd suggest a new question. – Chowlett Mar 26 '13 at 12:32

1 Answers1

0

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.

Chowlett
  • 45,935
  • 20
  • 116
  • 150
  • That worked. Then updated form to: = form_tag searches_path, :method => :get do = text_field_tag "term", "Search term" = submit_tag "Search" – steven_noble Mar 26 '13 at 12:34