我正在做一个blog application
. 我有一个add_article
模型和一个category
模型。这些relationship
模型之间是category has_many add_articles
. 忽略奇怪的名字。现在我已经创建了脚手架add_article
,所以在该_forms
部分是这样的。在表单中,用户将从下拉按钮中选择文章的类别。
<%= 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]:
请帮我解决这个错误。我已经成功迁移了我的数据库。还重新启动了服务器,但仍然无法正常工作。提前致谢。