2014-01-11 1 views
0

검색 양식을 작게 시작하고 기본 작업을 시작하려고합니다. 제공 할 수있는 도움에 미리 감사드립니다.내 간단한 레일즈 form_tag 검색 양식이 올바른 방법을 사용하여 결과를 제공하지 않는 이유는 무엇입니까?

레일즈 2.3 레거시 애플리케이션을 편집하고 기존 검색 폼을 수정하고 있습니다. 지금은 데이터베이스에있는 위치를 텍스트로 검색 할 수있는 필드가 있습니다 (도시와의 일치). 양식을 제출하면 "URL/location for searchs"에서 "URL/location for search? city = Los + Angeles"로 이동하지만 결과는 표시되지 않습니다. 내 기록을 토대로 볼 때 문제는 올바른 시각을 나타내지 않는다는 것입니다.

폼 페이지 (

<% form_tag search_path, :method => 'get' do %> 
    <%= text_field_tag :city, params[:city] %> 
    <%= submit_tag "Search", :name => nil %> 
    <% end %> 

결과 페이지 (results.html.erb)

<% for location in @site_matches %> 
<h3><%= location.name %></h3> 
<% end %> 

컨트롤러 (search_controller.rb)

index.html.erb
class SearchController < ApplicationController 
    def index 
    render :layout => 'mylayout' 
    end 

    def results 
    @site_matches = Location.find(:all, :conditions => ["city = ?", params[:city]]) 
    render :layout => 'mylayout' 
    end 
    end 

로그인

Processing SearchController#index (for X at X) [GET] 
    Parameters: {"city"=>"Los Angeles"} 
    Rendering template within layouts/mylayout 
    Rendering search/index 
    Completed in 9ms (View: 9, DB: 0) | 200 OK [URL/search-for-locations?city=Los+Angeles] 

경로

다시
map.resources :search 
    map.search '/search-for-locations', :controller => 'search', :action => 'index' 

, 나는이와 당신의 도움을 주셔서 감사합니다!

답변

0

많은 시행 착오 끝에 나는 "결과"동작이 "보기"렌더링을하지 못한다는 것을 발견했습니다. 내 경로에 아래 추가 :

map.resources :search, :collection => { :index => :get, :results => :get } 

는 또한

<% form_tag url_for(:controller => 'search', :action => 'results'), :method => 'get' do %> 

내 때 form_tag 변경 그리고 그것은 모두가 지금 작업입니다!

관련 문제