Topic: Problem using a one-to-many relationship
I have a problem using a one-to-many relationship in my ruby code.
Yes, I have searched through this forum and many others to get the exact changes I need to make to my code to get the whole thing working but could not find a correct one to go with.
Here is my set up so far -
1. Have 2 models - person and role. The person and role have a many-to-one relationship with the person.role_id pointing to role.id.
2. Made changes in the two models like this.
person.rb ---> belongs_to :role.role_id;
role.rb --->has_many :person;
3. I want to show the roles when creating a person, so I added this code in my _forms.rhtml of person view.
@roles = Role.find(:all, :order => "id")
collection_select(:role, :name, @roles, :id, :name)
4. The drop down appears all right, but when creating a person, the role_id goes as NULL so i am not able to associate a person to a role.
Any ideas on what else I should be doing to get this working.?