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

对着背影说爱祢 提交于 2019-12-08 01:44:33

问题


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.


回答1:


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'  %>


来源:https://stackoverflow.com/questions/17484343/how-to-change-the-default-value-of-check-box-in-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!