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'' %> <!--[form:gallery_image]--> <p><label for="gallery_image_caption">Caption</label><br/> <%= text_field ''gallery_image'', ''caption'' %></p> <p><label for="gallery_image_thumbnail_path">Thumbnail path</label><br/> <%= text_field ''gallery_image'', ''thumbnail_path'' %></p> <p><label for="gallery_image_fullsize_path">Fullsize path</label><br/> <%= text_field ''gallery_image'', ''fullsize_path'' %></p> <p><label for="gallery_image_gallery">Gallery</label><br/> <%= @galleries = Gallery.find(:all, :order => "name") collection_select(:gallery_id, :gallery_id, @galleries, :id, :name) %> <!--[eoform:gallery_image]--> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Will Gant 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'' %> > > <!--[form:gallery_image]--> > <p><label for="gallery_image_caption">Caption</label><br/> > <%= text_field ''gallery_image'', ''caption'' %></p> > > <p><label for="gallery_image_thumbnail_path">Thumbnail path</label><br/> > <%= text_field ''gallery_image'', ''thumbnail_path'' %></p> > > <p><label for="gallery_image_fullsize_path">Fullsize path</label><br/> > <%= text_field ''gallery_image'', ''fullsize_path'' %></p> > > <p><label for="gallery_image_gallery">Gallery</label><br/> > <%= @galleries = Gallery.find(:all, :order => "name") > collection_select(:gallery_id, :gallery_id, @galleries, :id, :name) > %> > <!--[eoform:gallery_image]--> > > 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.comi 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/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Sorry about the slow response. That seemed to fix the issue. Man, this framework is awesome! Stewart <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: Will Gant 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.comi 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---