Collection_Select and Foreign keys

Hello all,
I have two models (Gallery and Gallery_Image). Gallery_Image has a
gallery_id property that acts as a foreign key. The model files look as
follows:

class Gallery < ActiveRecord::Base
has_many :Gallery_Images
end

class GalleryImage < ActiveRecord::Base
belongs_to :Gallery
end

I altered the _form.rhtml file for Gallery_Image to look like the
following:

<%= error_messages_for ‘gallery_image’ %>

Caption
<%= text_field 'gallery_image', 'caption' %>

Thumbnail path
<%= text_field 'gallery_image', 'thumbnail_path' %>

Fullsize path
<%= text_field 'gallery_image', 'fullsize_path' %>

Gallery
<%= @galleries = Gallery.find(:all, :order => "name") collection_select(:gallery_id, :gallery_id, @galleries, :id, :name) %>

The gallery_id value is not being set in the database. Do I need to do
something in the controller? I know this is a stupid noob question, but
I would very much appreciate the help.

Also, should I move the “@galleries = …” part into the
gallery_images_controller and out of the view? I would think that I
should, but it looks like it would end up being repeated in the
controller (since it would have to be there for both new and update).
Any thoughts?

Thanks,
Will


Get your email and more, right on the new Yahoo.com

Will G. wrote:

Hello all,
I have two models (Gallery and Gallery_Image). Gallery_Image has a
gallery_id property that acts as a foreign key. The model files look as
follows:

class Gallery < ActiveRecord::Base
has_many :Gallery_Images
end

class GalleryImage < ActiveRecord::Base
belongs_to :Gallery
end

I altered the _form.rhtml file for Gallery_Image to look like the
following:

<%= error_messages_for ‘gallery_image’ %>

Caption
<%= text_field 'gallery_image', 'caption' %>

Thumbnail path
<%= text_field 'gallery_image', 'thumbnail_path' %>

Fullsize path
<%= text_field 'gallery_image', 'fullsize_path' %>

Gallery
<%= @galleries = Gallery.find(:all, :order => "name") collection_select(:gallery_id, :gallery_id, @galleries, :id, :name) %>

The gallery_id value is not being set in the database. Do I need to do
something in the controller? I know this is a stupid noob question, but
I would very much appreciate the help.

Also, should I move the “@galleries = …” part into the
gallery_images_controller and out of the view? I would think that I
should, but it looks like it would end up being repeated in the
controller (since it would have to be there for both new and update).
Any thoughts?

Thanks,
Will


Get your email and more, right on the new Yahoo.com

i am not sure about this but i think its your collection select in your
form
I am assuming your doing somehting like this in your controller for the
action of the form…

def create_gallery_image
@gallery_image = Gallery_Image.new(:params[:gallery_image])
end

if you are then your not passing all of the form details in the params
hash

try this:
collection_select(“gallery_image”, “gallery_id”, @galleries, :id, :name)

in place of this:
collection_select(:gallery_id, :gallery_id, @galleries, :id, :name)

Sorry about the slow response. That seemed to fix the issue. Man, this
framework is awesome!

Stewart [email protected] wrote:
Will G. wrote:

belongs_to :Gallery

end

I altered the _form.rhtml file for Gallery_Image to look like the
following:

<%= error_messages_for ‘gallery_image’ %>

Caption

<%= text_field ‘gallery_image’, ‘caption’ %>

Thumbnail path

<%= text_field ‘gallery_image’, ‘thumbnail_path’ %>

Fullsize path

<%= text_field ‘gallery_image’, ‘fullsize_path’ %>

Gallery

gallery_images_controller and out of the view? I would think that I
should, but it looks like it would end up being repeated in the
controller (since it would have to be there for both new and update).
Any thoughts?

Thanks,
Will


Get your email and more, right on the new Yahoo.com

i am not sure about this but i think its your collection select in your
form
I am assuming your doing somehting like this in your controller for the
action of the form…

def create_gallery_image
@gallery_image = Gallery_Image.new(:params[:gallery_image])
end

if you are then your not passing all of the form details in the params
hash

try this:
collection_select(“gallery_image”, “gallery_id”, @galleries, :id, :name)

in place of this:
collection_select(:gallery_id, :gallery_id, @galleries, :id, :name)


Posted via http://www.ruby-forum.com/.


New Yahoo! Messenger with Voice. Call regular phones from your PC and
save big.