Selection field using foreign key (Multiple references)


after hours of trying I am stuck with the following. I have a Class for
courses (called GdFb here) with multiple references to Class GdPerson

class GdFb < ActiveRecord::Base
  belongs_to :va_plan,
             :foreign_key => "va_plan",
             :class_name => "GdPerson"

  belongs_to :va_org,
             :foreign_key => "va_org",
             :class_name => "GdPerson"

and a Class for Persons:

  class GdPerson < ActiveRecord::Base
    has_many :gd_fbs

Now I want selection fields that allow me to edit the fields va_plan and
va_plan by selecting from existing entries in the GdPerson-Table.

I have tried many code snippets like
<% @personen = GdPerson.find(:all).collect { |c| [, ] } %>
<%#= collection_select('gd_fb', 'va_plan', @personen, :id, :name, {},
:multiple => false) %>

But none of them worked. Can someone help?


...finally I figured it out: The Parameter for belongs_to _must not_
have the same name as for "foreign_key"

Classfiles now contain:

class GdFb < ActiveRecord::Base
  belongs_to :va_plan,
             :foreign_key => "va_plan_id",
             :class_name => "GdPerson"

class GdPerson < ActiveRecord::Base
  has_many :gd_fbs

The migration files:

class CreateGdFbs < ActiveRecord::Migration
  def self.up
    create_table :gd_fbs do |t|
      t.column :va_plan_id, :integer

class CreateGdPeople < ActiveRecord::Migration
  def self.up
    create_table :gd_people do |t|
      t.column :name :string

Creating a selection list that updates the foreign-key relation
correctly works this way:

<%= f.collection_select(:va_plan_id, GdPerson.find(:all), :id, :name,
{:prompt => true}) %>