I'm Not Sure How To Implement this form. 

I'm setting up a Tournament Management app. When a User Creates a 
Tournament they pick the contact methods that the tournament will use for 
contacting participants. This List is defined by the Values seeded into 
Contact Methods. When another User Registers for the Tournament, They Can 
Pick From any of the Tournament's Contact Methods and if neccessary provide 
optional information. 

I'm not really sure how to setup the form but what i want it to look like 
this: 

<https://lh3.googleusercontent.com/-soN19ipHYyc/WIZTVWtYmZI/AAAAAAAAAXw/LaPPNZm5FfcmGlG1VZ0T-6AOP4hsl4egwCLcB/s1600/Desired%2BForm.PNG>



My Code

*Models*

class ContactMethod < ActiveRecord::Base
    has_and_belongs_to_many :tournaments
    has_and_belongs_to_many :registrations
end


class Tournament < ActiveRecord::Base
  has_and_belongs_to_many :contact_methods
end



class Registration < ActiveRecord::Base
  has_and_belongs_to_many :contact_methods
end


*Schema*
  create_table "contact_methods_registrations", force: :cascade do |t|
    t.integer "contact_method_id"
    t.integer "registration_id"
    t.string  "value"
  end

  create_table "contact_methods_tournaments", force: :cascade do |t|
    t.integer "contact_method_id"
    t.integer "tournament_id"
  end

*Form*

<fieldset class="form-group">
      <legend>Contact Method</legend>
      <%= hidden_field_tag("registration[contact_methods][]", nil) %>
      <% @tournament.contact_methods.order(:name).each do |contact| %>
          <div class="form-check">
            <label class="form-check-label">
              <%= check_box_tag("registration[contact_methods][]", 
contact.id, contact.id.in?(@registration.contact_methods.collect(&:id))) %> 
             <%= contact.name %>
            </label>
          </div>
          <div>
            <label>Your <%= contact.name %> Username</label>
            <%= text_field_tag "registration[contact_methods][]" %>
          </div>

        <% end %>
    </fieldset>


Thanks. 

-Hillary


-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to