Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default value of check_box ? in Ruby on Rails

How to change the default value of check_box ?

views/doctors/_form.html.erb

<%= form_for(@doctor) do |f| %>
  <%= f.label :pass %><br>
  <%= f.check_box :pass, {checked: true, checked_value: "yes", unchecked_value: "No"}  %>
  <%= f.submit %>
<% end %>

The data type of :pass attribute was string, But still it was not created any value for :pass attribute in DB. So, I changed the data type of :pass attribute into boolean.

Now it is working with True and False

But, I Just want to change the True and False into Yes and No

Please someone help me.

like image 747
Arun Avatar asked Jul 05 '13 08:07

Arun


1 Answers

According to this, the correct syntax is:

check_box(object_name, method, options = {}, checked_value = "1", unchecked_value = "0")

So, you should change your code to this:

 <%= f.check_box :pass, { checked: true }, 'yes', 'no'  %>
like image 124
Francisco QV Avatar answered Oct 21 '22 18:10

Francisco QV