Note that there are some explanatory texts on larger screens.

plurals
  1. POfields_for with radio buttons in rails 3.2
    primarykey
    data
    text
    <p>i currently do have a form for a event-signup, with unlimited amount greater one of participants in signup-form, so you can append forms via javascript, which i copied form the fields_for generator of the first must-be participant.</p> <p>Now i have a gender-field, which is just called :gender, and like 10 other inputs for other personal data.</p> <p>the genderfield however is the only one which is not send for each and every participiant. the field is just missing.</p> <p>the fields_for helper named it for example:</p> <pre><code>event[participants][][email] event[participants][][gender] </code></pre> <p>when i add 3 participants, i get an array like:</p> <pre><code>[{email: email1, gender: male}, {email:email2}, {email:email3}] </code></pre> <p>set to rails.</p> <p>since a radio-button is grouped by its name, i thought i might add the the index to the empty brackets, to have it like</p> <pre><code>event[participants][1][gender] </code></pre> <p>for the 2nd participant.</p> <p>this leads to </p> <pre><code>ERROR TypeError: expected Array (got Rack::Utils::KeySpaceConstrainedParams) for param `participants' </code></pre> <p>in Webrick.</p> <p>I am a bit confused of how to continue, giving all the inputs the index maybe, which feels not like rails-way at all.</p> <p>Any suggestions how to get this to work? my aim is to to get the gender sent for each participant.</p> <p>Best regards and thanks, daniel</p> the code, simplified: <p>the form:</p> <pre><code>= form_for @signup do |f| - participant_count = @signup.participants.count - @signup.participants.each_with_index do |participant,index| = f.fields_for "participants[]", participant do |p| = render :partial=&gt;'participant_form', | :locals=&gt;{:p=&gt;p, :participant=&gt;participant, :index=&gt;index, :participant_count =&gt; participant_count} </code></pre> <p>the _participant-partial, for one input that works and the gender:</p> <pre><code>%table %tr %th Gender / Only sent for the first participant:( %span * %td =p.radio_button :gender, 'male' %span Male =p.radio_button :gender, 'female' %span Female %tr %th Name %span * %td = p.text_field :first_name / this works just fine! for EACH participant. </code></pre> <p>results in this html code:</p> <pre><code> &lt;input id="event_participants__first_name" name="event[participants][][first_name]" size="30" type="text" value="" /&gt; and &lt;input id="event_participants__gender_male" name="event[participants][][gender]" style="float:left; margin-right: 20px;" type="radio" value="male"&gt; for each participant. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload