I am wondering how should i proceed with a rails form search like twitter to search multiple models.
I have implemented a search model/controller which will search based on the textbox and will eventually have ajax. But i am just wondering how can i implement it in my header file. Rendering may do is job but not sure how to call the searches controller.
Thanks in advance. Followed this tutorial http://railscasts.com/episodes/111-advanced-search-form
One approach would be to create a Search class. Create a form partial that has a query input that when submitted, is send to the Search class. Search will then come up with a collection of search results, which you then output to a separate view. Having a Search class allows you to keep additional capabilities to your search–additional models and ways to rank results.
Here is an skeletal example…
In your searching code for each class, use the ‘elements’ method to search through the individual query objects.
For the form
Routes.rb
Then a Search controller with a ‘query’ action. In this controller, simply do
Add a view ‘search’ for this controller action, where you render your @results. Your results will be a collection of individual objects from different classes, so your view can handle each item separately, which can be handled with additional partials, based on the object class.