gpt4 book ai didi

ruby-on-rails - Rails : form_for and radio buttons

转载 作者:行者123 更新时间:2023-12-04 18:31:41 24 4
gpt4 key购买 nike

我的 form_for 中有以下内容

<div class="multiple_students">
<%= f.label :multiple_classes, "Do you teach multiple classes?" %>
<%= f.radio_button :multiple_classes, 1, checked: @user.multiple_classes?, class: 'multiple_classes', data: { question: 'What is your average class size?' } %> <%= f.label :multiple_classes, "Yes", class: 'multiple_classes' %>
<%= f.radio_button :multiple_classes, 0, checked: @user.multiple_classes?, class: 'multiple_classes', data: { question: 'How many kids do you teach?' } %> <%= f.label :multiple_classes, "No", class: 'multiple_classes' %>
</div>
<div class="number_of_students hide">
<%= f.label :students %>
<%= f.text_field :students, :class=>"student_count required digits" %>
</div>

出于某种原因,即使用户的 multiple_classes 属性在数据库中被选择为 true( multiple_classes 是数据库中的 bool 类型),也始终会检查“否”

最佳答案

好的,如果您只想使用 radio_buttons,请检查以下内容并让我知道这是否有效。

<%= f.radio_button :multiple_classes, "1", checked: @user.multiple_classes?, class: 'multiple_classes', data: { question: 'What is your average class size?' } %> <%= f.label :multiple_classes, "Yes", class: 'multiple_classes' %>
<%= f.radio_button :multiple_classes, "0", checked: @user.multiple_classes?, class: 'multiple_classes', data: { question: 'How many kids do you teach?' } %> <%= f.label :multiple_classes, "No", class: 'multiple_classes' %>

10 加上引号并尝试....

它不是一个答案......它只是一个想法......

关于ruby-on-rails - Rails : form_for and radio buttons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15640470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com