Rails - SimpleForm 中默认选择的单选按钮:集合
我对 SimpleForm 中的单选按钮没什么问题。
当我使用
= f.association :manufactureType, :collection => ManufactureType.all, :as => :radio
Rails 时,只会生成几个单选按钮,但没有一个被选中。 我希望默认选择第一个单选按钮。我怎样才能做到呢?
谢谢
I've litte problem with radiobuttons in SimpleForm.
When i use
= f.association :manufactureType, :collection => ManufactureType.all, :as => :radio
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?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果将制造类型传递到视图中,则可以执行以下操作:
或者
If you pass in the manufacture types into the view, you can do the following:
Or
我的例子稍微复杂一些,其他答案都不适合我,因为没有可供参考的集合或模型。
My example was slightly more complicated, none of the other answers worked for me since there was no collection or model to reference.
根据操作员的评论,添加此参数对我有用:
from op's comment, adding this parameter worked for me:
这是我的有效代码的摘录:
Here is an excerpt of my code which works: