Rails applications don't update boolean field

I have a basic Rails form (using rails-bootstrap-forms for formatting) and I would like the radio button to set a boolean object field. Here is a code snippet (abbreviated for brevity):

<%= bootstrap_form_for(@comment) do |f| %>

  <%= f.text_field :name, label: "Name (required)", label_class: "whiteClass" %>
  <%= f.text_field :email, label_class: "whiteClass" %>
  <%= f.form_group :public  do %>
    <%= f.radio_button :public, true, label: "Public", label_class: "whiteClass", inline: true, checked: true %>
    <%= f.radio_button :public, false, label: "Private (Only Paul will see)", label_class: "whiteClass", inline: true %>
  <% end %>
  <%= f.submit "Send" %>

<% end %>

      

I tried to get the radio buttons to respond to vanilla rail shapes but was not successful. Any help is appreciated. Thank.

+3


source to share


3 answers


Try adding a value to your radio buttons:



<%= f.radio_button :public, true, label: "Public", label_class: "whiteClass", value: true, inline: true, checked: true %>
<%= f.radio_button :public, false, label: "Private (Only Paul will see)", label_class: "whiteClass", value: false, inline: true %>

      

0


source


You might want to take a look

I think you just need to add



validates_inclusion_of :public, :in => [true, false]

      

+1


source


Try specifying "true"

both "false"

instead of true

and false

:

<%= f.form_group :public  do %>
  <%= f.radio_button :public, "true", label: "Public", label_class: "whiteClass", inline: true, checked: true %>
  <%= f.radio_button :public, "false", label: "Private (Only Paul will see)", label_class: "whiteClass", inline: true %>
<% end %>

      

Hope it helps!

0


source







All Articles