0

I am trying to make radio buttons with simple form. I have the following code:

<%= f.input :payment_method, as: :radio_buttons, input_html:{value: 'venmo', id: 'venmo', style: 'float: left;'}%> 
<%= f.input :payment_method, as: :radio_buttons, input_html: {value: 'checking_account', id: 'checking_account', style: 'float: left'}, required: true  %>

For some reason, this is creating 4 radio buttons instead of 2 with labels "yes" and "no" that i don't want. Here is what it looks like:

enter image description here

Here is the html that is generated:

<div class="input radio_buttons required freelancer_account_mimic_payment_method">
    <label class="radio_buttons required" for="checking_account">
        <abbr title="required"></abbr>
         Payment method
    </label>
    <span class="radio radio">
        <input id="checking_account" class="radio_buttons required" type="radio" value="true" style="float: left" required="required" name="freelancer_account_mimic[payment_method]" aria-required="true"></input>
        <label class="collection_radio_buttons" for="freelancer_account_mimic_payment_method_true">
            Yes
        </label>
    </span>
    <span class="radio radio">
        <input id="checking_account" class="radio_buttons required" type="radio" value="false" style="float: left" required="required" name="freelancer_account_mimic[payment_method]" aria-required="true"></input>
        <label class="collection_radio_buttons" for="freelancer_account_mimic_payment_method_false">
            No
        </label>
    </span>
</div>

How do I fix this so only two radio buttons appear with labels that I choose?

Philip7899
  • 4,599
  • 4
  • 55
  • 114
  • Possibly the same as http://stackoverflow.com/questions/746387/labels-for-radio-buttons-in-rails-form ? – nishantjr Jun 23 '14 at 16:07
  • Thanks, but not a duplicate. My question is for simple form - not the regular rails form helpers. Also, that question does not explain the extra radio buttons popping up. – Philip7899 Jun 23 '14 at 16:09
  • You seem to be using radiobuttons (plural), they're using radiobutton (singular). I think the plural version create a Yes/No buttons – nishantjr Jun 23 '14 at 16:11
  • Removing the `float: left` would let you see whats happening better. I tend to avoid floats and use `display: inline` or `inline-block` since floats mess with layout in annoying ways. – nishantjr Jun 23 '14 at 16:13
  • Ok, I will try that. I changed it to singular and the server logs say "ActionView::Template::Error (No input found for radio_button):" – Philip7899 Jun 23 '14 at 16:15
  • there is no such thing with simple form, only f.input – Philip7899 Jun 23 '14 at 16:22
  • Looking at the Collection section of the documentation, would `f.input :payment_method, collection: ['Checking Account', 'Venmo']` work – nishantjr Jun 23 '14 at 16:33

0 Answers0