Sandy Thomson
2009-Apr-04 16:10 UTC
Creating a parent with grandparent_id from grandchild model
Hi, I have a situation where I have mapping table to link two models (effectively linking a grandparent and grandchild with a child and parent respectively) Here are the models: class Town < ActiveRecord::Base has_many :venues end class Venue < ActiveRecord::Base has_many :venue_aliases belongs_to :town validates_presence_of :town end class VenueAlias < ActiveRecord::Base belongs_to :venue end The list of towns already exists and is ultimately fixed, and for each new venue_alias a venue must be assigned or created (with a town_id) and assigned. I would like to do this all in one form, preferably with a nice autocomplete so that the user can either: 1. Enter the venue name and where it already exists assign the venue_id to the venue alias or 2. Enter the venue name and a town name, so that the new venue/town_id combo is created and subsequently the new venue_id is assigned to the venue_alias I''ve been through Ryan Bates'' screencasts but they generally deal with creating children at the same time as parents, so is there a way of doing it the other way around as it were? Thanks in advance... -- 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?hl=en -~----------~----~----~----~------~----~------~--~---