我有一個操作員searchPerson,它將一個名稱作爲參數,並重定向到該人員的詳細信息,如果它發現該人員,則呈現包含錯誤消息的searchPerson.html.erb。rails url rewriting
我想總是有http://localhost/person代替http://localhost/person/searchPerson
,所以我說的路線
map.connect "person/", :controller => 'person', :action => 'searchPerson'
所以當我輸入http://localhost/person我可以看到頁面searchPerson.html.erb 但是當我執行搜索它呈現的搜索人和url變成http://localhost/person/searchPerson
我的功能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
如何避免這種情況? 感謝