If that is the case, then how would you define the relationship where Bars can be created independently of a Foo, but then associated with one and only one Foo at a later time or perhaps never associated to a Foo?
I tried using "has_one :foo" in bar.rb instead of "belongs_to :foo" but the results are no different. My real application has Contacts (Bars) and Invitations (Foos). Contacts can be created and managed on their own. Invitations can be created, and then existing contacts can be associated with one and only one Invitation at a time. On May 3, 3:38 pm, storitel <[email protected]> wrote: > I'm another newbie... but it seems to me that if a bar really belongs > to a foo, you shouldn't be creating it independently of its foo? ie it > should only make sense to create a bar in the context of its parent > foo. > > i'm guessing that this means you may have chosen the wrong > relationships in your model? > > On 3 May, 20:10, Jeremy Savoy <[email protected]> wrote: > > > > > > > I outlined my issue in another post, but I no longer seem to be able > > to reply to that post so I'll start the thread again here, hoping that > > someone can help me to resolve it. > > > Lets take the simple fooBar application example, foo and bar are the > > models, foo has many bars and bar belongs to foo. > > > If you create a few bars, and then go to create a foo, I would expect > > the foo form to allow you to select and add any previously created > > bars to the new foo. This does not work, you are only allowed to > > create new bars on the new foo form, not associate previously created > > bars. A select-one is not even present on the new or edit foo form, > > only a "+" button next to "Bar". > > > To reproduce: > > > #> hobo fooBar > > #> cd fooBar > > #> ./script/generate hobo_model_resource foo name:string > > #> ./script/generate hobo_model_resource bar name:string > > #> vi app/model/foo.rb ---> add "has_many :bars, :accessible => true" > > #> vi app/model/bar.rb ---> add "belongs_to :foo" > > #> ./script/generate hobo_migration > > > ## Create a few bars > > ## Create a new foo, and notice that you cannot associate any of the > > previously created bars, but only create new bars on the foo form. > > > Now, if you add a join table, bar_assignments, and say that foo > > has_many bars through bar_assignments, then you can add previously > > created bars to the new foo. I do not understand the difference in > > behavior in the view layer just by using a join table, if someone > > could please explain that would be helpful in finding resolution to > > the issue. > > > I appreciate the answers given on the previous post, but unfortunately > > none of them solved the issue. I have tried explicitely specifying > > <bar-view:> as a select-one, etc etc --- none of these work. I'm not > > sure if this is a problem that should be fixed by changes in the model > > or changes in the view layer... > > > Please feel free to try for yourself, the foobar application takes > > only about 60 seconds to set up .... > > > Thanks for your time, and your patience with a Hobo/Rails/Ruby > > newbie .... > > > -- > > You received this message because you are subscribed to the Google Groups > > "Hobo Users" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group > > athttp://groups.google.com/group/hobousers?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Hobo Users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/hobousers?hl=en. -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
