如何在rails中正确使用单选按钮? [英] How to use radio button correctly in rails?

查看:15
本文介绍了如何在rails中正确使用单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一些单选按钮,但我不知道该怎么做.在 this 问题之后,我的设置工作几乎正确,但我对此很陌生,不知道为什么我不能完全弄清楚.所以我正在做的是放置一个标签来对布尔值进行分组,然后有标记为是和否的单选按钮.如果用户单击是的标签,它应该选择单选按钮是(现在他们只能单击按钮本身).这是我的代码如下:

I'm trying to create some radio buttons and I'm not sure how to. Following this question I've got it set up working almost correct, but I'm new to this and not sure why I can't figure it out completely. So what I'm doing is putting a label to group the boolean and then have radio buttons which are labeled Yes and No. If the user clicks the label of Yes it should select the radio button yes (right now they can only click the button itself). This is my code as follows:

  <div class="field">
    <%= f.label :autolyse %><br />
    <%= f.label :autolyse, "Yes", :value => "Yes"  %>
    <%= f.radio_button :autolyse, true%>
    <%= f.label :autolyse, "No", :value => "No" %>
    <%= f.radio_button :autolyse, false, :checked => true %>
  </div>

第一个标签用于组,它将组标记为Autolyse".然后我想要一个是"的标签,如果选择它将设置为真,然后显然下一个是假的.如何正确设置?

The first label is for the group, it labels the group "Autolyse". Then I want a Label for "Yes", which if selected will will set true, and then obviously the next one is for False. How do I get this set up correctly?

推荐答案

参见label(object_name, method, content_or_options = nil, options = nil, &block)

  <div class="field">
    <%= f.label :autolyse %><br />
    <%= f.label :autolyse, "Yes", :value => "true"  %>
    <%= f.radio_button :autolyse, true %>
    <%= f.label :autolyse, "No", :value => "false" %>
    <%= f.radio_button :autolyse, false, :checked => true %>
  </div>

这篇关于如何在rails中正确使用单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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