You need to use Ruby's select
tag combined with Ruby's options_from_collection_for_select
. You can set your prompt to true
or add a custom prompt and required
must be in curly braces and its value set to true
. For example:
<%= select('trophy','metric', options_from_collection_for_select(Metric.find(:all), :id, :name),{:prompt => 'Select Metric'},{:required => true})%>
Where:
-trophy
is the name of an instance variable or a model object
-metric
is is the attribute of that instance variable. This is typically a field/column of the table whose data you're displaying.
-:id
is the key
-:name
is the result