Having a Bit of trouble displaying unique results from my database. I have a database called "Activities". Each Activity has an associated Sport through sport_id. There may be many activities with the same sport_id.
I want to display a list of all sports linked to the activities database without displaying (for example "Football") twice.
FYI : Venues have many Facilities and Facilities have many Activities.
Controller:
@sports = Sport.all
@activities = Activity.paginate(page: params[:page])
@facilities = Facility.where(venue_id: @venue.id)
View:
<% @facilities.each do |f| %>
<% @activities.find(:all, :conditions => "facility_id == #{f.id} ").each do |a| %>
<li><%= Sport.find(a.sport_id).name %>, (<%= a.facility_id %>)</li>
<% end %>
<% end %>
This shows:
- Football, (2)
- Hockey, (2)
- Hockey, (2)
- Football, (5)
I would like to display just:
- Football
- Hockey
Any ideas?