h2. collection_select

use collection_select

<pre><code><%= collection_select("job", "client" , @clients, "id", "name") %></code></pre>

@clients holds a collection of Client objects, id ends up being the value and name ends up being the text displayed

this would create:

<pre><code><select name="job[client]">
 <option value="1">Francisco Hernandez</option>
 <option value="2">James Earl</option>
</select> </code></pre>

*Note*: <code>collection_select</code> does not mark the currently selected item - use <code>select</code> instead. For more information on this, see "Issue 1125":http://dev.rubyonrails.org/ticket/1125 

h2. select helper

I used the select helper to give the user a choice to select the sex of a person.

The helper code is as follows:
<pre><code><%= select( "member", "sex", { "male" => "M", "female" => "F"}) %>
</code></pre>

This would render this HTML:
<pre><code><select id="member_sex" name="member[sex]">
<option value="F">female</option>
<option value="M" selected="selected">male</option>
</select></pre></code>


Rails would assign the values M or F for this attribute in the database, and pre-select the right value if the view is rendered for editing.

h2. options_from_collection_for_select and multiple selected values

When trying to get multiple selected values from a <code><SELECT></code> tag into @@params@, call your parameter something with [] on the end.  That way rails knows it's multiple.

So instead of 
<pre><code><select name="job[techs]" size="5" multiple="multiple">
</pre></code>

Use:
<pre><code><select name="job[techs][]" size="5" multiple="multiple">
</pre></code>

h3. Example

<pre><code><% @selected = @job.technician.collect { |t| t.technician_id.to_i } %>
<select name="job[techs][]" size="5" multiple="multiple">
  <%= options_from_collection_for_select(@techs, "id", "full_name", @selected) %>
</select></pre></code>
