I have 2 tables in my DB – an “illness” table and a “symptoms” table.
I’ve implemented a generic search for searching both tables.
My goal is to display the results in the result page, each result should be a hyperlink that leads to the result “show” page (illness/id/show or symptom/id/show).
As i’m passing generic results to the result page, I don’t really know whether the current result is an illness or a symptom. I wonder what is the best way to get this information (Should I try to collect this informaiton in the controller and somehow pass it to the html? should I somehow run another query from the html?)
I’m using rails 3.x, and my controller code looks like this:
class SearchController < ApplicationController
def index
@results = Illness.search(params[:search]) + Symptom.search(params[:search])
respond_to do |format|
format.html # index.html.erb
format.json { render json: @results }
end
end
end
Thanks,
Li
You don’t have to be worried about it. Let the Rails to serve it:
And you’ll get the proper link based on the result’s type.
And one more. What the
showin URL has to do with theshowaction in your examples like:symptom/id/show? Theshowaction is mapped by default toGET /model/idpath.