Ruby on Rails
Saturday, March 31, 2012
Hi!
I'm creating a simple signup form where people can sign up for a camp. They should be able to add a contact person and also sign up other people (such as family members).
Two models:
Application
has_many :participants
accepts_nested_attributes_for :participants
Participant
belongs_to :application
I have some trouble with the contact person, which is also a participant. I guess I should add something like this:
Application
has_many :participants
belongs_to :contact_person, :class_name => "Participant", :foreign_key => "contact_person_id"
accepts_nested_attributes_for :participants, :contact_person
Ok, so then I try to set up my nested form. In my ApplicationsController#new method I do this:
def new
@application = Application.new
2.times { @application.participants.build }
1.times { @application.contact_person.build }
end
So, any ideas what I have done wrong? It was a while ago I fiddled with nested forms like this...
Thanks!
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/RMu_z5Xl3zwJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment