Reputation: 1
I'm trying to do a simple model association. I have an 'issues' table and a 'statuses' table. Every issue has a status. Table 'issues' has a 'status_id' column.
issue.rb
belongs_to :status
status.rb
has_many :issues
issues/index.html.erb
...
<% @issues.each do |issue| %>
...
<td><%= issue.status.title %></td>
...
I get the following error:
undefined method `title' for nil:NilClass
SOLUTION: Create all models associations BEFORE adding any records into the database (i.e. using scaffold).
Upvotes: 0
Views: 49
Reputation: 1
SOLUTION: Create all models associations BEFORE adding any records into the database (i.e. using scaffold).
Upvotes: 0
Reputation:
undefined method 'title' for nil:NilClass
means issue.status
is nil
.
You could do something like
<%= issue.status.title if issue.status %>
Upvotes: 2