def search if params[:q] query = params[:q] # First find the user hits... @users = User.find_by_contents(query, :limit => :all) # ...then the subhits. personals = Personal.find_by_contents(query, :limit => :all) #flash[:notice] = personals.size faqs = Faq.find_by_contents(query, :limit => :all) # Now combine into one list of distinct users sorted by last name. hits = personals + faqs #flash[:notice] = hits.size @users.concat(hits.collect { |hit| hit.user }).uniq! # Sort by last name (requires a personal for each user). @users.each { |user| user.personal ||= Personal.new } @users = @users.sort_by { |user| user.personal.last_name } #@users = @users.paginate(:page => params[:page], :per_page => 10) @invalid = true end end Sir, i want to implement a search function. I got a code from one of the book where the objective is to find a user based on a name or any thing else.. Here ''User'' is a users table.. ''Faq'' is table which contains info abt the user.. n ''Personal'' contains personal info abt user.. Can u please help me in understanding the following lines of code.. # Now combine into one list of distinct users sorted by last name. hits = personals + faqs #flash[:notice] = hits.size @users.concat(hits.collect { |hit| hit.user }).uniq! # Sort by last name (requires a personal for each user). @users.each { |user| user.personal ||= Personal.new } @users = @users.sort_by { |user| user.personal.last_name } i want to implement searching by tag... Thank u.. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.