# Thinking Sphinx: tabbed interface

**URL:** <https://www.ruby-forum.com/t/thinking-sphinx-tabbed-interface/145468>\
**Category:** Rails\
**Created:** [August 10, 2008, 9:48am UTC](https://www.ruby-forum.com/t/thinking-sphinx-tabbed-interface/145468 "2008-08-10T09:48:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [August 10, 2008, 9:48am UTC](https://www.ruby-forum.com/t/thinking-sphinx-tabbed-interface/145468/1 "2008-08-10T09:48:51Z")

</div>

I’m implementing search based on the recent Railscast on Thinking  
Sphinx. I have a reasonably complex tabbed interface for the results.  
The searches controller handles the searches, and :collections, like  
:comments =\> :get, handle when the user wants to break down the results  
in to a category (the interface has a tab for each model), giving urls  
like /searches/comments/:search. My searches controller only performs  
one find in a before\_filter called load\_results, so when a user clicks  
on a category tab, the params[:search] is passed over in the link\_to for  
the tab and the before\_filter loads the same results (am I right in  
thinking that the controller is only performing the search once, or do I  
need to do more to ‘cache’ the load\_results in the before filter? I’m  
aiming to only do one search the entire time the user in in the searches  
controller, and to rip out only the models we need for each :collection.  
So far, I haven’t worked out how to, a) combine the model searches in to  
one @results variable in the before filter, and, b) how to only take out  
‘result in @results’ for the :collections for each model;

# a) something like this?

private

def load\_results  
@results = Comment.search params[:search] + User.search  
params[:search]  
end

# b) my views are doing logic which probably belongs in the controller

actions,

# I don’t know how to do an equivalent conditional in the controller

action…  
\<% for result in @results %\>  
\<% if result.class.name == “Comment” %\>  
\<%= render :partial =\> “comments/comment”, :locals =\> { :comment =\>  
result } %\>  
\<% end %\>  
\<% end %\>

Any ideas on either of these?
