views:

36

answers:

1

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?

+2  A: 

That's ruby issue, not rails. Locally you probably have 1.8.7, and heroku has 1.8.6. The Enumerable#count method was introduced in 1.8.7: compare http://ruby-doc.org/core-1.8.6/classes/Enumerable.html and http://ruby-doc.org/core-1.8.7/classes/Enumerable.html.

neutrino
Hey thanks for the quick reply and you are right! It turns out that I can migrate my application (running on Heroku aspen) to Heroku Bamboo (which supports 1.8.7 and 1.9.1) See: http://docs.heroku.com/bamboo .
DJTripleThreat