2013-05-16 60 views
0

我正在使用blog application。我一个add_article模型和一个category模型。 这些型号之间的relationshipcategory 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]: 

请帮我这个错误。我成功迁移了我的数据库。还重新启动了服务器,但仍无法正常工作。 在此先感谢。

+1

如果它在本地工作,那么您的Heroku数据库中可能没有任何类别的文章。如果文章应该总是有一个类别,然后更新/删除有问题的文章,否则你可以做一些像'add_article.category.try(:title)' –

+0

好吧。是的,这可能会发生。因为我还没有在heroku上创建类别。让我检查。 –

+0

耶感谢它的工作现在..它发生,因为我有没有分类的文章。 –

回答

1

一个或多个add_article记录没有与之相关的category记录所有add_article及其category,并检查其中为空可能是你错过了一些地方在正常播种的数据库。

1

你有没有任何以前在heroku db add_articles没有类别分配?如果是这样,你将不得不将类别分配给那些已经存在的类,或者删除现有的数据库并创建添加分类,或者拯救add_atricle.category.title语句。

相关问题