This is a simple question but I can't figure out as I am new to rails.
My controller has a @neighborhoods variable which contains neighborhood records for each Business in the @businesses variable (each business has_one neighborhood)
In my view, I want to print out:
- Each unique neighborhood name
- How many of each unique neighborhood name (can be multiple since it is taken from the @businesses variable)
Currently I have:
<% @neighborhoods.uniq{|x| x.name}.each do |neighborhood| %>
<p><%= neighborhood.name %></p>
<%= @neighborhoods.where{name = neighborhood}.count %>
<% end %>
I know the above code is wrong, but it illustrates what I am trying to do. How can I achieve this?
validates :neighborhood, :uniqueness => {:scope => :name}@neighborhoods.where{name = neighborhood}.count