2010-08-27 87 views
3

現在,如果我轉到我擁有的模型的索引操作,那麼如果沒有現有的數據,則不會顯示Rails爲我生成的基本數據表記錄在數據庫中。我做的是這樣的:Array.count在本地工作正常,但在heroku上休息

<% 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 %> 

這在當地適用。然而,當我把我的應用程序的Heroku,這會導致500錯誤和日誌說: ActionView::TemplateError (undefined method 'count' for []:Array) on line ...

所以我將其更改爲.length並能正常工作。誰能告訴我爲什麼?有人告訴我,這些是多餘的,軌道擺脫了.count,但我的理解是,.lengthArray函數,它告訴你在Array.count有多少項是一個ActiveRecord用於確定陣列中有多少項是實際的記錄在數據庫中。

任何人都可以爲我闡明這一點嗎?

回答

3

這是ruby問題,而不是rails。本地你可能有1.8.7,而heroku有1.8.6。在1.8.7中引入了Enumerable#count方法:比較http://ruby-doc.org/core-1.8.6/classes/Enumerable.htmlhttp://ruby-doc.org/core-1.8.7/classes/Enumerable.html

+0

嘿感謝您的快速回復,你是對的!事實證明,我可以將我的應用程序(在Heroku aspen上運行)遷移到Heroku Bamboo(支持1.8.7和1.9.1)。請參閱:http://docs.heroku.com/bamboo。 – DJTripleThreat 2010-08-27 06:09:49

相關問題