Right now, if I go to the index action of the model that I have, I am not showing the main data table that rails generates for me if there are no existing records in the database. I am doing something like:
<% if @my_records.count > 0 %>
<table>
<tr>
<th>...</th>
<th>...</th>
<th>...</th>
<th>etc</th>
</tr>
<% @my_records.each do |my_record| %>
<tr>
<td><%=h my_record.etc %></td>
<td><%=h my_record.etc %></td>
<td><%=h my_record.etc %></td>
<td><%=h my_record.etc %></td>
</tr>
<% end %>
</table>
<% end %>
It works locally. However, when I click my application on the hero, it causes a 500 error, and the log says:
ActionView::TemplateError (undefined method 'count' for []:Array) on line ...
So I change it to .length, and it works great. Can someone tell me why this is so? Someone told me that they are redundant and the rails are spared .count, but I realized that .length- this is a function Arraythat tells you how many elements are in Arrayand .countthere was a ActiveRecordmethod for determining the number of elements in an array - these are the actual records in the database.
- ?