如何更改 check_box 的默认值?在 Ruby on Rails 中 [英] How to change the default value of check_box ? in Ruby on Rails

查看:44
本文介绍了如何更改 check_box 的默认值?在 Ruby on Rails 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改 check_box 的默认值?

How to change the default value of check_box ?

views/doctors/_form.html.erb

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

:pass 属性的数据类型是 string,但它仍然没有为 DB 中的 :pass 属性创建任何值.因此,我将 :pass 属性的数据类型更改为布尔值.

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.

现在它正在处理True and False

但是,我只是想把True and False改成Yes and No

请有人帮助我.

推荐答案

根据 this,正确的语法是:

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

这篇关于如何更改 check_box 的默认值?在 Ruby on Rails 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆