but gives me error "Couldn't find Patient with ID=find" (The above
link generates the URL example.com/patients/find?
search_string=Hillcrest)
I tried playing around with routes.rb, but got nowhere. What am I
doing wrong?
In addition to what Gul has said, assuming you have the default
map.resources :patients then you need to tell rails about your find
action ( take a look at the routing guide at guides.rubyonrails.org
(hint: :collection ))
Since find is not one of the standard actions, have you included a specific route for patients/find? The default routes generated by map.resources :patients will assume that find is a patient id, expecting to see patients/2 for example.
Having thought further about this I would suggest that you may going about it the wrong way anyway. I think what you are trying to do is select a set of patients for display. The default action for showing a set of patients is the index action, which by default would show all patients and is accessed by example.com/patients. You could use the URL example.com/patients?search_string=Hillcrest (or whatever) and test for the presence of params[:search_string] in the index method of the controller. Then no special routing is required.
Make sure it is before map.resources :patient otherwise this will be seen first and you will get the problem you have described. Also I do not put a leading / when using map.connect but I do not know whether that is an issue or not. So I would put map.connect ‘patients/find’ …