Reputation: 1936
I m working on a blog application
. Ive one add_article
model and one category
model.
The relationship
between these models is category has_many add_articles
. Ignore the weird name. Now i ve created the scaffold of add_article
, so in the _forms
section is like this.
in the forms the user will select the category of the article from the drop down button.
<%= f.label :category_id %><br />
<%= f.collection_select :category_id, Category.all, :id, :title, include_blank: true, :class => "short"%>
Also the show page:
<p>
<b>Category</b>
<%= @add_article.category.title %>
</p>
Now index page
<% @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>
Now the whole thing is working perfectly locally but it is not working on heroku.
Showing this error
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]:
Please help me about this error. Ive migrated my database successfully. Also restarted the server but still it is not working. Thanks in advance.
Upvotes: 0
Views: 59
Reputation: 164
Did you have any previous add_articles on heroku db which don't have category assigned? If so you will have to assign category to those already there, or drop exisiting db and create fress add_articles, or rescue add_atricle.category.title statement.
Upvotes: 1
Reputation: 9146
one or more of the add_article
records do not have a category
associated with it log all the add_article
and their category
and check where is is null may be you missed some where in seeding the database properly.
Upvotes: 1