hellomello
hellomello

Reputation: 8587

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

Upvotes: 5

Views: 4844

Answers (3)

Fellow Stranger
Fellow Stranger

Reputation: 34013

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

Upvotes: 1

Rajarshi Das
Rajarshi Das

Reputation: 12320

This way..

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

Upvotes: 2

Yanhao
Yanhao

Reputation: 5294

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

Upvotes: 7

Related Questions