= form_with model product url admin_products_path local true do f div class=form-group label for=title class=col-sm-2 control-label商品名称label = ftext_field title class form-control div div
在Rails中,可以使用f.radio_button方法来生成radio按钮的表单元素。下面是使用f.radio_button方法来生成上架的radio按钮的示例代码:
<div class="mb-3">
<label for="on_sale" class="col-sm-2 control-label">上架</label>
<div>
<div class="form-check form-check-inline">
<%= f.radio_button :on_sale, true, id: "inlineRadio1" %>
<label class="form-check-label" for="inlineRadio1">是</label>
</div>
<div class="form-check form-check-inline">
<%= f.radio_button :on_sale, false, id: "inlineRadio2" %>
<label class="form-check-label" for="inlineRadio2">否</label>
</div>
</div>
</div>
在上面的代码中,f.radio_button方法的第一个参数是属性名,这里是:on_sale,第二个参数是选项的值,这里分别是true和false,第三个参数是传递给radio按钮的HTML选项,这里是id: "inlineRadio1"和id: "inlineRadio2"。
这样,当用户提交表单时,@product对象的on_sale属性将被设置为所选的值
原文地址: https://www.cveoy.top/t/topic/icow 著作权归作者所有。请勿转载和采集!