我是否可以在集合中的每个单选按钮之间显示换行符?
f.collection_radio_buttons(
:chosen,
[['A1', 1],['A2', 2], ['A3', 3]],
:last,
:first,
html_options: { class: 'form-control' }
)
我无法进行测试,但我认为这会有所帮助:
<%= f.collection_radio_buttons(:chosen, [['A1', 1],['A2', 2], ['A3', 3]], :last, :first, html_options: { class: 'form-control' }) do |b| %>
<%= b.label { b.radio_button + " " + b.text } %><br>
<% end %>
我就是这样做到的:
= residency.collection_radio_buttons :own,
[[true, 'I Own This Home'], [nil, 'I Rent'], [false, 'I Live Rent Free']],
:first,
:last,
item_wrapper_tag: :div, <-- MAGIC IS HERE
label: false do |rdb|
.d-block
= rdb.radio_button + rdb.label(class: 'p-l-1')
看起来form_tag版本允许通过块进行自定义,所以我认为这同样适用于form_for
http://apidock.com/rails/v4.0.2/ActionView/Helpers/FormOptionsHelper/collection_radio_buttons
也可以通过给方法一个块来定制元素的显示方式:
collection_radio_buttons(:post, :author_id, Author.all, :id, :name_with_initial) do |b| b.label { b.radio_button } end
所以你可以试试这个
<%= f.collection_radio_buttons(:chosen, [['A1', 1],['A2', 2], ['A3', 3]], :last, :first, html_options: { class: 'form-control' }) do |b| %>
<%= b.label { b.radio_button } %><br>
<% end %>