Hi,
I have a controller person with an action searchPerson which takes a name as parameter and redirects to the person details if it founds the person else it renders the searchPerson.html.erb with an error message.
I would like to always have http://localhost/person instead of http://localhost/person/searchPerson
so I added a route
map.connect "person/", :controller => 'person', :action => 'searchPerson'
so when I type http://localhost/person I can see the page searchPerson.html.erb but when I perform a search it renders searchperson and the url becomes http://localhost/person/searchPerson
my function 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
How to avoid that? thanks