In my ROR application using acts_as_solr plugin as a search engine which runs on top of Lucene library.
now, i am able to search the results as below in controller
def search
@user_class=User.find_by_solr("rajesh")
respond_to do |format|
format.html # search.html.erb
format.xml { render :xml => @user_class }
end
my question is how can i display the search results in search.html.erb page
presently doing as below
but getting error as
undefined method `each' for ActsAsSolr::SearchResults:0x463c2e4
Help me , Mahesh
Best Answer
Your
@user_class
object is not an array, but an instance of the classActsAsSolr::SearchResults
. To access the resulting documents, call itsdocs
method:Your
@user_class
object also contains other useful information like:See
lib/search_results.rb
in the acts_as_solr source code for all the available methods.