i really need some help on this. I searched the internet but couldn’t find a single solution to my problem.
I have got an index.html.erb file which displays some records which have been retrieved using a rather complex find_by_sql. Please see code below:
def index
@refprobes = Refprobe.paginate_by_sql ["select * from ref_probe
where RPR_OID in
(SELECT DISTINCT RPR_OID
FROM REF_PROBE
JOIN ISH_PROBE ON RPR_OID = PRB_MAPROBE
JOIN ISH_SUBMISSION ON PRB_SUBMISSION_FK = SUB_OID
JOIN SEC_USER_PI ON USP_PI_ID = SUB_PI_FK
WHERE USP_USER_FK = " + session[:user_id]+ ")"], :page => params[:page], :per_page => 10
end
Now i want to include a search field on top of my index.html.erb, which will allow user to filter those displayed entries based on the value inputted in the search field.
def self.search(search)
if search
find(:all, :conditions => ['name LIKE ?', "%#{search}%"])
else
find(:all)
end
end
The above code does not fit my requirements as i don’t want to search through all the records in the table. I want to restrict my search to only those entries displayed my index.html.erb.
How can i do this?
Many many thanks in advance for your help..
read about scopes