ruby on rails implement generic search -


i have 2 tables in db - "illness" table , "symptoms" table. i've implemented generic search searching both tables. goal display results in result page, each result should hyperlink leads result "show" page (illness/id/show or symptom/id/show).

as i'm passing generic results result page, don't know whether current result illness or symptom. wonder best way information (should try collect informaiton in controller , somehow pass html? should somehow run query html?)

i'm using rails 3.x, , controller code looks this:

class searchcontroller < applicationcontroller     def index         @results = illness.search(params[:search]) + symptom.search(params[:search])          respond_to |format|             format.html # index.html.erb             format.json { render json: @results }         end     end end 

thanks, li

you don't have worried it. let rails serve it:

   - @results.each |result|      = link_to 'show', result 

and you'll proper link based on result's type.

and 1 more. show in url has show action in examples like: symptom/id/show? show action mapped default get /model/id path.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -