2009-11-25 8 views
0

나는 사람이 매개 변수로 이름을 취하고 그 사람을 찾으면 오류 메시지가있는 searchPerson.html.erb를 렌더링하는 search searchPerson을 가진 컨트롤러 담당자가 있습니다.레일즈 URL 재 작성

내가 수행 할 때 내가 페이지 searchPerson.html.erb 을 볼 수 있습니다 http://localhost/person을 입력하지만 때 난 항상 내가

map.connect  "person/", :controller => 'person', :action => 'searchPerson' 

그래서 경로를 추가 http://localhost/person 대신 http://localhost/person/searchPerson

의하고 싶은 검색자가 렌더링하고 검색하는 URL은 http://localhost/person/searchPerson

내 기능 검색 사용자

def searchPerson 

    flash[:error]=nil 
    @name=params[:name] 

    #if a name is provided 
    if(@name!=nil) 

     #trying to find the person with the name 
     ret = Person::lookup @name 

     #error, the person cannot be found 
     if ret[:err] 
     flash[:error]="We could not find this person" 
     #person found, user is redirected to the person details 
     else 
     redirect_to url_for(:controller => 'person', :action => 'details', :id => ret[:person].id) 
     end 
    end 
end 

어떻게 피할 수 있습니까? 감사

답변

0

redirect_to 실제로 는 다른 URL로을 리디렉션합니다. 대신 세부 정보와 검색을 동일한보기에서 렌더링하지 않는 것이 좋습니다. @person에 검색 결과를 입력하십시오. 보기에서 @person이 nil인지 확인하고 적절한 메시지를 표시하십시오.

또한 기본 레일 scaffolding부터 시작하는 것이 좋습니다. 검색을 다루지는 않지만 시작할 수있는 좋은 곳입니다.

0

는 다음

redirect_to를 시도 : 컨트롤러 => '사람': 행동 => 무기 호 : ID => nil을