How do a search a table for similar records and displaying count - Ruby on Rails

Posted by bgadoci on Stack Overflow See other posts from Stack Overflow or by bgadoci
Published on 2010-04-14T04:52:25Z Indexed on 2010/04/14 4:52 UTC
Read the original article Hit count: 199

Filed under:

I have created a table in my Ruby on Rails application that I am building called Tags. It is a blog application so I allow the user to associate tags with a post and do this through a :posts, :has_many => tags and Tag belongs_to :post association.

Now that I have my Tags table I am trying to see how I would render the view such that it displays the tag and tag count. (it should be noted that I am trying to render this in the /views/posts/index.html.erb file).

For instance, if there are 10 entries in the Tag table for tag_name Sports. How can I display Sports (10) in the view. I am not looking to do this for a specific tag but rather, somehow search the table, combine like tags and display a list of all tags with counts next to them. (I really want these to be a link to a list of posts that contain that tag but I learned early on only to ask one question at a time).

Hope that makes sense.

© Stack Overflow or respective owner

Related posts about ruby-on-rails