How do I create a radio_button_tag for every value of a constant array? E.g., I have this constant array: VALID_ORIENTATIONS = ["Straight", "Gay", "Bisexual"] . A user is presented with a form to search for other users according to sexual orientation. Currently, the form looks like this:
<div class="form_row"> <label for="orientation">Sexual Orientation:</label> <%= radio_button_tag :orientation, "Straight", params[:orientation] == 'Straight', :id => "Straight" %>Straight <%= radio_button_tag :orientation, "Gay", params[:orientation] == 'Gay', :id => "Gay" %>Gay <%= radio_button_tag :orientation, "Bisexual", params[:orientation] == 'Bisexual', :id => "Bisexual" %>Bisexual <%= radio_button_tag :orientation, "", params[:orientation].blank?, :id => "Any" %>Any </div> This is not DRY. How can I iterate through every value in the constant array to make these radio buttons? Is partial appropriate for this? The array has only three values. Also: the blank in the last radio button is obviously not in the array. It's there to allow the user to not use this search criterion. Is there a better way for a user to unselect a radio button without choosing any other? Thanks. -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.