Excuse me for the seemingly basic question, but I'm new to Rails and I can't seem to google anything useful.
I have two models: Works has_many Pictures.
Both models have a :title.
If, in my works/index.html.erb file, I include:
<%= work.title %>
The title of the Work shows up as expected.
Likewise, if I include:
<%= work.pictures[0] %>
The class id of the first related record from Pictures shows up, because (I believe) they are correctly linked via has_many and belongs_to.
But if I do this instead:
<%= work.pictures[0].title %>
I get a NoMethodError: undefined method 'title' for nil:NilClass
I know the Pictures model has a title field. Obviously I'm not doing it right; what am I missing?
Thanks!