Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby on rails: radio buttons for collection select

I have a collection select:

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

What is the radio button for this method?

Thanks

like image 997
hellomello Avatar asked Aug 30 '13 05:08

hellomello


3 Answers

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

like image 102
Yanhao Avatar answered Nov 14 '22 15:11

Yanhao


This way..

<%= f.collection_radio_buttons :role, User::ROLES  %>
like image 20
Rajarshi Das Avatar answered Nov 14 '22 15:11

Rajarshi Das


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 %>
like image 1
Fellow Stranger Avatar answered Nov 14 '22 15:11

Fellow Stranger