Topic: undefined local variable or method
I am trying to tidy up an index page I'm working on. Here is the one that works:
<h1>Listing cities</h1>
<%= link_to 'New city', new_city_path %>
<table>
<tr>
<th>Name</th>
<th>Ghome</th>
<th>Image url</th>
</tr>
<% for city in @cities %>
<tr>
<td><%=h city.name %></td>
<td><%=h city.ghome %></td>
<td><%=h city.image_url %></td>
<td><%= link_to 'Show', city %></td>
<td><%= link_to 'Edit', edit_city_path(city) %></td>
<td><%= link_to 'Destroy', city, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
I have altered this page to try to make it look better, but I get an error. It says "undefined local variable or method 'city' for ..."
Here is the code I use that gives me the problems:
<div id="city-list">
<h1>Listing Cities</h1>
<%= link_to 'New city', new_city_path %>
<table>
<% for cities in @cities %>
<tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
<td>
<%= image_tag city.image_url, :class => 'list-image' %>
</td>
<td class="list-details">
<dl>
<dt><%=h city.name %></dt>
<dd><%=h city.ghome %></dd>
</dl>
</td>
<td class="list-actions">
<%= link_to 'Show', city %><br />
<%= link_to 'Edit', edit_city_path(city) %><br />
<%= link_to 'Destroy', city,
:confirm => 'Are you sure?',
:method => :delete %></td>
</td>
</tr>
<% end %>
</table>
</div>
I'm looking at it and if the line <%=h city.name %> works in the first one, why won't it work in the second one?
Last edited by amnion (2010-10-30 21:41:52)