Right now, if I go to the index action of a model that I have, I don't show the basic table of data that rails generates for me if there are no existing records in the database. I do 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 %>
This works locally. However, when I push my app to heroku, this 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 fine. Can anyone tell me why that is? Someone has told me that these were redundant and rails got rid of .count
but my understanding was that .length
is an Array
function that tells you how many items are in the Array
and .count
was an ActiveRecord
method for determining how many items in the array were actual records in the database.
Can anyone shed light on this for me?