我正在使用blog application
。我一個add_article
模型和一個category
模型。 這些型號之間的relationship
是category has_many add_articles
。忽略奇怪的名字。現在我已經創建了add_article
的腳手架,所以在_forms
部分是這樣的。 用戶將從下拉按鈕中選擇文章的類別。Heroku顯示錯誤無類
<%= f.label :category_id %><br />
<%= f.collection_select :category_id, Category.all, :id, :title, include_blank: true, :class => "short"%>
還顯示頁面:
<p>
<b>Category</b>
<%= @add_article.category.title %>
</p>
現在索引頁
<% @add_articles.each do |add_article| %>
<tr id="tr_<%= add_article.id %>">
<td><%= add_article.topic %></td>
<td><%= add_article.category.title %></td>
<td><%= add_article.refrences %></td>
現在整個事情是可以正常使用本地,但它不工作在Heroku。
顯示此錯誤
Started GET "/add_articles" for 122.170.95.103 at 2013-05-16 05:44:23 +0000
2013-05-16T05:44:23.751555+00:00 app[web.1]: Processing by AddArticlesController#index as JS
2013-05-16T05:44:23.773397+00:00 app[web.1]: 27: <td><%= add_article.topic %></td>
2013-05-16T05:44:23.773397+00:00 app[web.1]: 29: <td><%= add_article.refrences %></td>
2013-05-16T05:44:23.771049+00:00 app[web.1]: Rendered add_articles/index.js.erb within layouts/ajax (12.0ms)
2013-05-16T05:44:23.773397+00:00 app[web.1]: ActionView::Template::Error (undefined method `title' for nil:NilClass):
2013-05-16T05:44:23.773397+00:00 app[web.1]: 25: <% @add_articles.each do |add_article| %>
2013-05-16T05:44:23.771297+00:00 app[web.1]: Completed 500 Internal Server Error in 20ms
2013-05-16T05:44:23.771049+00:00 app[web.1]: Rendered add_articles/_index.html.erb (11.6ms)
2013-05-16T05:44:23.773397+00:00 app[web.1]: 26: <tr id="tr_<%= add_article.id %>">
2013-05-16T05:44:23.773397+00:00 app[web.1]: 28: <td><%= add_article.category.title %></td>
2013-05-16T05:44:23.773397+00:00 app[web.1]:
2013-05-16T05:44:23.773397+00:00 app[web.1]: 30: <td><%= link_to '<i class="icon-eye-open"></i> '.html_safe, add_article, :remote => true %></td>
2013-05-16T05:44:23.773397+00:00 app[web.1]: app/views/add_articles/_index.html.erb:28:in `block in _app_views_add_articles__index_html_erb__2991715183487747607_48161360'
2013-05-16T05:44:23.773758+00:00 app[web.1]: app/views/add_articles/_index.html.erb:25:in `_app_views_add_articles__index_html_erb__2991715183487747607_48161360'
2013-05-16T05:44:23.773397+00:00 app[web.1]: 31: <td><%= link_to '<i class="icon-edit"></i> '.html_safe, edit_add_article_path(add_article), :remote => true %></td>
2013-05-16T05:44:23.773758+00:00 app[web.1]: app/controllers/add_articles_controller.rb:8:in `index'
2013-05-16T05:44:23.773758+00:00 app[web.1]: app/views/add_articles/index.js.erb:1:in `_app_views_add_articles_index_js_erb__265206221585688192_48175820'
2013-05-16T05:44:23.773758+00:00 app[web.1]:
請幫我這個錯誤。我成功遷移了我的數據庫。還重新啓動了服務器,但仍無法正常工作。 在此先感謝。
如果它在本地工作,那麼您的Heroku數據庫中可能沒有任何類別的文章。如果文章應該總是有一個類別,然後更新/刪除有問題的文章,否則你可以做一些像'add_article.category.try(:title)' –
好吧。是的,這可能會發生。因爲我還沒有在heroku上創建類別。讓我檢查。 –
耶感謝它的工作現在..它發生,因爲我有沒有分類的文章。 –