Friday, April 12, 2013

Re: [Rails] Join table query error

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

On 13/04/2013, at 10:56 AM, Dave Castellano <lists@ruby-forum.com> wrote:

> 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
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate