Rails - SimpleForm 中默认选中的单选按钮:collection [英] Rails - Default selected radiobutton in SimpleForm :collection

查看:29
本文介绍了Rails - SimpleForm 中默认选中的单选按钮:collection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 SimpleForm 中的单选按钮有一些小问题.

I've litte problem with radiobuttons in SimpleForm.

当我使用

= f.association :manufactureType, :collection => ManufactureType.all, :as => :radio

Rails 只生成很少的单选按钮,但没有一个被选中.我希望默认选择第一个单选按钮.我该怎么做?

Rails simply generates few radiobuttons, but none of them are selected. I want first radiobutton to be selected by default. How can i make it?

谢谢

推荐答案

如果您将制造类型传入视图,您可以执行以下操作:

If you pass in the manufacture types into the view, you can do the following:

:checked => @manufacture_types[0]

:checked => ManufactureType.first

这篇关于Rails - SimpleForm 中默认选中的单选按钮:collection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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