# Count dupliate element

**URL:** <https://www.ruby-forum.com/t/count-dupliate-element/176229>\
**Category:** Rails\
**Created:** [September 27, 2009, 11:48am UTC](https://www.ruby-forum.com/t/count-dupliate-element/176229 "2009-09-27T11:48:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wangshuyi54](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/b4bc9f/32.png) [@wangshuyi54](https://www.ruby-forum.com/u/wangshuyi54)\
**Post date:** [September 27, 2009, 11:48am UTC](https://www.ruby-forum.com/t/count-dupliate-element/176229/1 "2009-09-27T11:48:19Z")

</div>

Tables:  
booking: show\_id (belongs\_to: show)

show: name, venue\_id (has\_many :bookings belongs\_to :venue)

venue: location, capacity ( has\_many : shows)

NOW, I use this view,

# Listing venue rank
\<% @bookings.each do |booking| %\> 

```
 <%=h booking.show.venue.location %>

  <br />
  </tr></table>

```

it can get the booking venue list like that :

Listing venue rank  
Location: www  
Location: www  
Location: weee  
Location: weee  
Location: www

but I want 2 make this page like that:

Listing venue rank  
Location: www 3  
Location: weee 1

I want to count the dupliate locations and show the number. I think it  
will use distinct or count to modfy the controllers, but i do not figure  
out. please give me some sugguestion.

class ShowsController \< ApplicationController  
def index

```
@shows = Show.find(:all, :order => "date")
@venue = Venue.find(:all)

```

class BookingsController \< ApplicationController

def index  
@bookings = Booking.find(:all, :order =\> “show\_id, date”)  
@venue = Venue.find(:all)  
@shows = Show.find(:all)

class VenuesController \< ApplicationController

def index  
@venues = Venue.all
