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

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

5 Comments

hope you have permitted it into the params
can you show us the code for creating tasks in the controller?
you have to permit parameters like params.require(:task).permit(:name, :is_done )
before you save the task can you show us whats inside params?
After some random undo and redo, it magically worked for some reason. I can't find out what have I done which caused it to work. Thanks for your help anyw

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.