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 })%> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Feb 28, 8:56 am, Eva <eva.hai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 })%>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
neharohan.chopra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-29 19:00 UTC
Re: change drop down list to radio buttons
Color.find(:all).each do |color| <input type="radio" id="color_id" name="color_id" value="<%=color_id %>" /><%=color.rgb_value%> end On Feb 29, 12:09 pm, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> 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 > > On Feb 28, 8:56 am, Eva <eva.hai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 })%>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---