# Searching by tag

**URL:** <https://www.ruby-forum.com/t/searching-by-tag/184573>\
**Category:** Rails\
**Created:** [March 4, 2010, 7:11pm UTC](https://www.ruby-forum.com/t/searching-by-tag/184573 "2010-03-04T19:11:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![manish\_belsare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@manish\_belsare](https://www.ruby-forum.com/u/manish_belsare)\
**Post date:** [March 4, 2010, 7:11pm UTC](https://www.ruby-forum.com/t/searching-by-tag/184573/1 "2010-03-04T19:11:09Z")

</div>

Hello sir,  
i hav implemented a web application in which a user posts a question and  
the answer will be provided by an EXPERT who has logged in…  
The question posted wil hav tag,title and ques\_string…  
now i want to implement a search method so that the user can search a  
question based on the tag and the answer will also be retrieved…  
for this i hav used ‘acts\_as\_ferret’ plugin…  
ma question is can u help me in implementing the search method so that  
on clickin the query along with the answer will be retrieved bases on  
the tag given by user…

code implemented by me for search is:

def search  
if params[:q]  
query = params[:q]  
# First find the user hits…  
@psts = Post.find\_by\_contents(query, :limit =\> :all)  
# …then the subhits.

```
@psts.each { |post| post ||= Post.new }
@psts = @psts.sort_by { |post| post.tag }
@invalid = true

```

end  
end

partial form for search…

\<% form\_tag({ :action =\> “search” }, :method =\> “get”) do %\>

  
  
   
\<%= text\_field\_tag “q”, params[:q] %\>  
   
   

  
\<% end %\>

In ma implementation…  
Post belongs to user…  
and Answer belongs to posts
