Peter
Peter

Reputation: 467

Ruby view unable to map values to boolean

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

Upvotes: 0

Views: 119

Answers (1)

Vishal
Vishal

Reputation: 828

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>

Upvotes: 1

Related Questions