drop down menu - Rails 3 dropdown select boxes? -
i working on simple intranet application made rails 3.1.
i have model links has following fields:
name:string url:string colour:string
i have put colour attribute class in view, so:
<a href="linkaddress" class="<%= link.colour %>">link name</a>
at moment in new link form have simple form input in user can type , become href class expected.
what create dropdown list of preset options, these options red, green , blue (as example). seems simple, don't think there need helper.
i have read few other questions , answers on , seem show examples have name followed id number. want have code below:
<select name="colour"> <option value="red">red</option> <option value="green">green</option> <option value="blue">blue</option> </select>
i'm sure simple can't head around it. i've read rails api info , select_for_tag has confused me!
just use standard select element in form set colour variable:
<%= f.select :colour, options_for_select([["red", "red"], ["green", "green"]], @link.colour) %>
Comments
Post a Comment