0

I want a radio button with 2 value. It's default value is set as false. Currently, the data is not saved into the database. I have scoured SO and look at ruby's form_helper docs and still can't seem to find out what's wrong with my code.

This code is supposed to be in index.html.erb

  <div>
    <%= form.label :is_done, "Done", :value => true %>
    <%= form.radio_button :is_done, true %>
  </div>
  <br>

I have also tried this method

  <div>
    <%= form.radio_button :is_done, true %>
    <%= form.label :is_done, "True", :value => true %>
    <%= form.radio_button :is_done, false %>
    <%= form.label :is_done, "False", :value => false %>
  </div>

Edit: both versions are working perfectly, some random undo and redo fixed something

Eyeslandic
  • 14,553
  • 13
  • 41
  • 54
Peter
  • 437
  • 1
  • 4
  • 20

1 Answers1

1

Based on this and this questions, it should be like this:

  <div>
    <%= form.label :is_done, "Done", :value => "true" %>
    <%= form.radio_button :is_done, true, checked: "true" %>
  </div>
Vishal
  • 818
  • 8
  • 20