11155
(-- --)
May 2, 2013, 8:00pm
1
Hi, I'm a novice and could use help with a join table question. I have
a join table "galleries_questions".
I can't figure out how to query it for pictures in a selected gallery.
Controller:
@gallery = Gallery.where("minisection_id" =>
session[:minisection_id]).first
@pictures = Gallery.find(@gallery ).pictures
View:
<% @pictures.each do |picture| %>
<%= image_tag picture.image_url.to_s %>
ERROR:
PGError: ERROR: column pictures.gallery_id does not exist
LINE 1: SELECT "pictures".* FROM "pictures" WHERE "pictures"."galle...
^
: SELECT "pictures".* FROM "pictures" WHERE "pictures"."gallery_id" =
11
Any suggestions?
Thanks
hassan
(Hassan Schroeder)
May 2, 2013, 8:37pm
2
I have a join table "galleries_questions".
I'll hope that's really 'galleries_pictures'
I can't figure out how to query it for pictures in a selected gallery.
How do you have the relationship defined in the models?
Controller:
@gallery = Gallery.where("minisection_id" =>
session[:minisection_id]).first
@pictures = Gallery.find(@gallery ).pictures
Not relevant, but @gallery.pictures would work there...
11155
(-- --)
May 3, 2013, 1:07am
3
Yes, its actually 'galleries_pictures'
class Gallery < ActiveRecord::Base
has_and_belongs_to_many :pictures
class Picture < ActiveRecord::Base
has_and_belongs_to_many :galleries
"Not relevant, but @gallery.pictures would work there..." Where?
hassan
(Hassan Schroeder)
May 3, 2013, 2:11am
4
If you don't top-post, this will be easier
class Gallery < ActiveRecord::Base
has_and_belongs_to_many :pictures
class Picture < ActiveRecord::Base
has_and_belongs_to_many :galleries
What does the migration for the creation of your join table look like?
"Not relevant, but @gallery.pictures would work there..." Where?
replacing '@pictures = Gallery.find(@gallery ).pictures'