# Change drop down list to radio buttons

**URL:** <https://www.ruby-forum.com/t/change-drop-down-list-to-radio-buttons/130469>\
**Category:** Rails\
**Created:** [February 28, 2008, 2:57pm UTC](https://www.ruby-forum.com/t/change-drop-down-list-to-radio-buttons/130469 "2008-02-28T14:57:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dbc845/32.png) [@Eva](https://www.ruby-forum.com/u/Eva)\
**Post date:** [February 28, 2008, 2:57pm UTC](https://www.ruby-forum.com/t/change-drop-down-list-to-radio-buttons/130469/1 "2008-02-28T14:57:02Z")

</div>

In my RoR app I would like to change a drop down list, which dispays a  
list of colors selected from the database. Instead I would like to  
create a radio button for each color. The user is allowed to check one  
color and this will be saved back into the database as the color for  
this user.  
I don’t know how to do this. Currently it looks like this:

\<%= select(:user, :color\_id, Color.find(:all).collect {|c| [ c.name,  
c.id ] }, { :include\_blank =\> false })%\>

---

<div class="post-metadata">

**Author:** ![Eva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dbc845/32.png) [@Eva](https://www.ruby-forum.com/u/Eva)\
**Post date:** [February 29, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/change-drop-down-list-to-radio-buttons/130469/2 "2008-02-29T18:10:12Z")

</div>

Color.find(:all).each do |color|  
\<%= select :user, :color\_id, color.id, :style=\>“background:  
##{color.rgb\_value};” %\>  
end

Okay, the style part is not really required but it might make for an  
interesting way for your users to select their color – they’d see it  
displayed on the UI.

HTH,  
AndyV

---

<div class="post-metadata">

**Author:** ![Eva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dbc845/32.png) [@Eva](https://www.ruby-forum.com/u/Eva)\
**Post date:** [February 29, 2008, 8:01pm UTC](https://www.ruby-forum.com/t/change-drop-down-list-to-radio-buttons/130469/3 "2008-02-29T20:01:19Z")

</div>

Color.find(:all).each do |color|  
\<%=color.rgb\_value%\>  
end
