title: How to get selected value in select in rails 3?
body: <p>I want to know how to get the selected value of <code>&lt;select&gt;</code>. I only know how to populate this.</p>
  
  <p>Here's is my code in <b><code>index.html.erb</code></b>. I used this to populate the <code>&lt;select&gt;</code> dropdown menu.</p>
  
  <pre><code>&lt;h1&gt;Trap&lt;/h1&gt;
  
  &lt;%= form_for @search do |f| %&gt;
   &lt;p&gt;
    Employee Code: 
    &lt;%= f.select(:empcode_contains, @employee.collect {|e| [ e.empcode,   e.id ]})  %&gt;
   &lt;/p&gt;
  
   &lt;p class="button"&gt;&lt;%= f.submit "Search" %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  
  &lt;p&gt;
   Sort by:
   &lt;%= sort_link @search, :empcode %&gt; |
   &lt;%= sort_link @search, :date_entry %&gt; |
  &lt;/p&gt;
  
  &lt;table&gt;
   &lt;tr&gt;
    &lt;th&gt;Empcode&lt;/th&gt;
    &lt;th&gt;Date entry&lt;/th&gt;
    &lt;th&gt;&lt;/th&gt;
    &lt;th&gt;&lt;/th&gt;
    &lt;th&gt;&lt;/th&gt;
   &lt;/tr&gt;
  
  &lt;% @traps.each do |trap| %&gt;
   &lt;tr&gt;
    &lt;td&gt;&lt;%= trap.empcode %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= trap.date_entry %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= link_to 'Show', trap %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= link_to 'Edit', edit_trap_path(trap) %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= link_to 'Destroy', trap, :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;&lt;/td&gt;
   &lt;/tr&gt;
  &lt;% end %&gt;
  &lt;/table&gt;
  
  &lt;br /&gt;
  
  &lt;%= link_to 'New Trap', new_trap_path %&gt;
  </code></pre>
  
  <p>And in my controller <b><code>traps_controller.rb</code></b>:</p>
  
  <pre><code>def index
   @search = Trap.search(params[:search])
   @traps = @search.all
   @employee = Employee.all
  
   Trap.all.each do |t|
     Employee.create(:empcode =&gt; t.empcode)
   end
  
   respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml =&gt; @traps }
   end
  end
  </code></pre>
  
  <p>Pls tell me how to get the selected value if the user selects a value. I don't have any idea.</p>