0

A person can compete in various events, but they must enter a partner's name for that event. This association is stored in an entry, which contains a field for the partner's name.

class Person < ActiveRecord::Base
    has_many :entries
    has_many :events, :through => :entries

    validates_presence_of :name
end

class Event < ActiveRecord::Base
end

class Entry < ActiveRecord::Base
    belongs_to :person
    belongs_to :event

    validates_presence_of :partner_name
end

The question is: How do you create a single page form that allows a person to enter themselves in multiple events and input their partners' names? I've tried to implement an all_entries method in the person model that will return an array of entry objects for all the available events, and an all_entries_attributes method that will update, create, and delete entry objects, but I can't seem to find a good, clean way to do this. I know this is a rather open ended question, but this must be a pattern that someone else in the rails community has encountered before, so I'm hoping there is a good solution to it.

Connor McKay
  • 580
  • 7
  • 13

2 Answers2

2

If you are still looking for the answer you might want to check out my question and answer that I found.

Community
  • 1
  • 1
ok32
  • 1,311
  • 12
  • 27
0

So you want a page in which you can create events for a user, and add people to those events

I won't give you a plain solution because there's some work to an implementation for this, but I will recommend checking out these railscasts about nested model forms

part1 and part2

Andrei S
  • 6,486
  • 5
  • 37
  • 54
  • Thanks Andrei, unfortunately this isn't really my problem. The issue here is in displaying checkboxes for a predetermined set of options, and allowing the user to enter extra information for the options they select. – Connor McKay Jan 04 '12 at 06:37