造型' collection_radio_buttons'

时间:2016-03-26 18:24:34

标签: ruby-on-rails ruby twitter-bootstrap styles

我可以设置这些样式,以便在集合中的每个单选按钮之间出现换行符吗?

f.collection_radio_buttons(
  :chosen,
  [['A1', 1],['A2', 2], ['A3', 3]],
  :last,
  :first,
  html_options: { class: 'form-control' }
)

3 个答案:

答案 0 :(得分:5)

我无法测试,但我认为这有助于:

<%= 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 %>

答案 1 :(得分:0)

看起来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 %>

答案 2 :(得分:0)

这是我实现的方式:

= 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')
相关问题