I have the following which outputs a select box:
<%= f.label :request_type_id %><br />
<% requestTypes = RequestType.all %>
<%= f.collection_select :request_type_id, requestTypes, :id, :title, :prompt => true %>
What is the rails method to instead output Radio Buttons?
For radio buttons you have to iterate yourself and output every radio button and its label. It's really easy in fact.
<% RequestType.all.each do |rt| %>
<%= f.radio_button :request_type_id, rt.id %>
<%= f.label :request_type_id, rt.title %>
<% end %>
Or in haml in case it's preferred over erb:
- RequestType.all.each do |rt|
= f.radio_button :request_type_id, rt.id
= f.label :request_type_id, rt.title
In Rails 4 there is a collection_radio_buttons for this:
<%= f.collection_radio_buttons :request_type_id, RequestType.all, :id, :title %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With