这将是我今天的最后一个问题(对不起,如果我问得太快了)
我收到错误undefined method 'map' for nil:NilClass
它说问题出在这一行:<td><%= image_tag @map.map.url %></td>
整个索引代码如下:
<h1>Listing maps</h1>
<table>
<tr>
<th>Carname</th>
<th>Map</th>
<th>Criticalcomponentlocations</th>
<th>Warnings</th>
<th>Additionalinfo</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @maps.each do |map| %>
<tr>
<td><%= map.carname %></td>
<td><%= image_tag @map.map.url %></td>
<td><%= map.criticalcomponentlocations %></td>
<td><%= map.warnings %></td>
<td><%= map.additionalinfo %></td>
<td><%= link_to 'Show', map %></td>
<td><%= link_to 'Edit', edit_map_path(map) %></td>
<td><%= link_to 'Destroy', map, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Map', new_map_path %>
地图控制器,索引:
def index
@maps = Map.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @maps }
end
end