2013-05-16 3 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]: 

이 오류에 대해 저를 도와주세요. Ive가 내 데이터베이스를 성공적으로 마이그레이션했습니다. 또한 서버를 다시 시작했지만 여전히 작동하지 않습니다. 미리 감사드립니다. add_article 기록

+1

로컬로 작동하는 경우 Heroku 데이터베이스에 카테고리가없는 기사가있을 수 있습니다. 기사가 항상 카테고리를 가지고 있다면, 문제가있는 것을 업데이트/삭제하십시오. 그렇지 않으면'add_article.category.try (: title)' –

+0

같은 것을 할 수 있습니다. ive가 아직 heroku에 카테고리를 만들지 않았기 때문에. 내가 체크해 볼게.!! –

+0

그래, 지금 그 일을 고마워. 내가 분류되지 않은 기사를 가지고 있기 때문에 일어났다. –

답변

1

하나 이상이 그와 관련된 category가 로그인하지 않아도 모든 add_articlecategory와 제대로 데이터베이스 시드의 일부 위치를 놓친 수 있습니다 null의 위치를 ​​확인합니다.

1

heroku db에 카테고리가 지정되지 않은 add_articles가 있습니까? 그렇다면 기존 데이터베이스에 범주를 지정하거나 기존 데이터베이스를 삭제하고 fress add_articles를 작성하거나 add_atricle.category.title 문을 복원해야합니다.