2013-03-26 3 views
0

내가 http://localhost:3000/searches에서 내 브라우저를 할 때, 나는 다음과 같은 오류 얻을 :pg_search를 사용하여 무한 루프가 발생하는 이유는 무엇입니까?

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 
+0

주기적 리디렉션처럼 보입니다. 'redirect_to searches_path'는 요청을 동일한 액션으로 다시 보내지 않습니까? – Chowlett

+0

나는 그것이 /app/views/searches.html.haml로 나를 보내 주었다고 생각했다. 이 페이지를 사용하여 검색 결과를 표시하고 검색어를 수집 할 계획이었습니다. 하지만 어떻게해야 프로세스를 두 가지 행동으로 나눌 수 있습니까? –

+0

'redirect_to' 라인을 꺼내십시오. 그렇게하면 레일스는 기본적으로'app/views/searches/index.html.haml'을 렌더링 할 것입니다. 그런 다음 양식에 게시하면 다시'index'를 요청하고 원하는 것을 만들어야합니다. – Chowlett

답변

0

; redirect_to searches_path은 요청을 동일한 작업으로 다시 보냅니다.

redirect_to 라인을 꺼내십시오. 그렇게하면 Rails는 기본적으로 app/views/searches/index.html.haml을 렌더링합니다. 그런 다음 양식에 게시하면 index을 다시 요청하고 원하는 것을 만들어야합니다.

+0

그게 효과가있다.그런 다음 업데이트 된 양식을 = form_tag searches_path, : method => : do do = text_field_tag ​​"용어", "검색어" = submit_tag "검색" –

관련 문제