我在 gem 上使用 acts as taggable 并试图创建一个漂亮的组按钮,但如果我正在编辑表单,它不会保持标记状态。我知道数据库确实保存了值。我什至可以在编辑时更改值并保存,但是当我返回到编辑按钮时,它不会显示保存了哪个按钮。
.btn-group{ data: { toggle: "buttons" } }
- ["Value1", "Value2", "Value3"].each do |item|
= f.label item, class: "btn btn-default" do
= f.radio_button :tag_list, item
= item
看起来像这样:
想要编辑这个:
我是否缺少一个可以显示值的简单方法?
最佳答案
将 checked
属性添加到您的 radio_button
:
= f.radio_button :tag_list, item, checked: f.object.tag_list.include?(item)
关于css - rails 4 bootstrap group buttons with acts as taggable on edit, not pushed down,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35117599/