Join table query error

Hi, I'm learning Rails and am getting an error following a query. I think I'm missing something simple and would appreciate guidance.

In controller: [code]@pictures = Question.find(session[:question_id]).pictures # Query through the join table[/code]

@picture : [#<Picture id: 44, title: "", remote_image_url: nil, contributor: "", created_at: "2013-04-10 11:16:34", updated_at: "2013-04-10 11:16:34", gallery_id: nil, image: "pict4.png">, #<Picture id: 46, title: "", remote_image_url: nil, contributor: "", created_at: "2013-04-12 23:39:18", updated_at: "2013-04-12 23:39:18", gallery_id: nil, image: "pict2.jpg">]

In view: <% @pictures.each do |picture| %> <%= image_tag(@picture.image %> <% end %>

Error: undefined method `image' for nil:NilClass

Thanks

The code in your view should be:

<% @pictures.each do |picture| %> <%= image_tag(picture.image %>

<% end %>

without @

Also I'm not sure what Question is, but your picture model seems to be missing a question_id... so your Question.find(session(:question_id).pictures will always be blank, won't it?

Julian

Ricardo Franco wrote in post #1105491:

The code in your view should be:

<% @pictures.each do |picture| %>     <%= image_tag(*picture*.image %> <% end %>

without *@*

Thank you Ricardo! (Must have been too tired...)

Julian Leviston wrote in post #1105496:

Also I'm not sure what Question is, but your picture model seems to be missing a question_id... so your Question.find(session(:question_id).pictures will always be blank, won't it?

Julian

The query is to find all pictures with the question id of session[:question_id] from a join table, so works fine.

Thanks you both for reply!

Dave