ruby on rails: radio buttons for collection select

寵の児 提交于 2019-11-30 17:39:18

问题


I have a collection select:

  <%= f.collection_select :role, User::ROLES, :to_s, :humanize %>

What is the radio button for this method?

Thanks


回答1:


There is no such helper in Rails 3. In Rails 4, it is collection_radio_buttons.




回答2:


This way..

<%= f.collection_radio_buttons :role, User::ROLES  %>



回答3:


No documentation found for the form builder, but this should work:

<%= f.collection_radio_buttons :my_attribute, my_hash.map {|k,v| [k,v]}, :first, :last do |b| %>
  <div class='my-class'>
    <%= b.radio_button %>
    <%= b.label %>
  </div>
<% end %>


来源:https://stackoverflow.com/questions/18525986/ruby-on-rails-radio-buttons-for-collection-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!