Dave Muench
2006-Aug-12 06:56 UTC
[Rails] issues with relationships and multiple objects on one form
Hello,
1. I have a form that edits a User and a Person at the same time. The
controller is for the User. Everything works fine, except the fields
that are populated by the Person fields lose state when validation
fails. Do I use params to populate the user? I have tried a bunch of
combinations with no luck.
2. The same users table has an integer column called
''primary_organization_id'', where Organization references many
User
records. The models are defined as:
class User < ActiveRecord::Base
belongs_to :primary_organization,
:class_name => ''Organization'',
:foreign_key => ''primary_organization_id''
class Organization < ActiveRecord::Base
has_many :primary_users,
:class_name => ''User'',
:foreign_key => ''primary_organization_id''
A select displays all Organizations on the User form, allowing the
relationship to be defined using the code:
<p><label for="user_primary_organization">Primary
Organization</label>
<%= collection_select(''user'',
''primary_organization_id'', @organizations,
''id'', ''name'') %>
</p>
When I create and save a new user everything works fine. When I open
the user to edit it, the relationship is correct, but when I try and
save existing user I get the error:
Unknown key(s): primary_organization_id
Any help would be greatly appreciated.
Thanks,
Dave
--
Posted via http://www.ruby-forum.com/.
Reasonably Related Threads
- Problem having two belongs_to of the same class type
- acts_as_tree and traversing parent/child relationships
- Self-Referential Many-To-Many relationships where the relationship itself has data.
- Any progress on undirected self-referential many to many relationships?
- problems returning collection_select info to controller
