Sorry for this newbie question but I cannot figure how I can do this..
I have the following City table
# Table name: cities
#
# id :integer
# name :string(255)
# country :string(255)
(note: I am not using a separate Country table as I use Geokit-rails and think it is simpler to store all Google queries in the same table. However It would be easier to have separate tables to render what I want through a belong_to/has_many association)
In my city/index view I want to loop all the cities for each countries in order to render something like:
United States
New York
San Francisco
Los Angeles
United Kingdom
London
Spain
Madrid
...
By now, What I can get is what it provided by scaffolding
Model
def index
@cities = City.all
end
View
<table>
<% for city in @cities %>
<tr>
<th><%= city.country %></th>
</tr>
<tr>
<td><%= city.name %></td>
</tr>
<% end %>
</table>
Rendering:
United States
Los Angeles
United States
New York
...
I didn't find any resource about this. I would be pleased if someone could help me (I don't know with which I have to start: find_by_ /params /each or collection?)
Thanks a lot!