Hi,
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
end
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| [ c.name, c.id ] } %>
<%#= collection_select(''gd_fb'',
''va_plan'', @personen, :id, :name, {},
:multiple => false) %>
But none of them worked. Can someone help?
TIA
--
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
-~----------~----~----~----~------~----~------~--~---
Dierk E.
2008-Jan-11 13:27 UTC
Re: Selection field using foreign key (Multiple references)
...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}) %>
--
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
-~----------~----~----~----~------~----~------~--~---