2013-07-08 72 views
0

我必須在下拉菜單中顯示員工姓名以及員工姓名。以下代碼顯示錯誤,如「無法將字符串轉換爲整數」有沒有解決此問題的方法?兩個數據在下拉菜單

在查看

<div class="input integer optional"><label class="integer optional control-label" for="assign_staff_subject_id">Subject</label><%= f.select :teacher_id, Teacher.all.map{|i| [i.employee_no,i.id] [i.first_name, i.id]} , :prompt => "--Select a Teacher--" %></div><br/> 

在哪種方式,我可以做到這一點?謝謝大家提前

+0

嘗試employee_no和id out this' <%= f.select:teacher_id,Teacher.all.map {| i | [i.id,「#{i.first_name} - #{i.employee_no}」]},:prompt =>「 - 選擇一位教師 - 」%>' –

回答

0

我猜你是想顯示在<li>標籤的FIRST_NAME和id

<%= f.select :teacher_id, Teacher.all.map{|i| ["#{i.first_name}, #{i.id}", "#{i.employee_no},#{i.id}"]} , :prompt => "--Select a Teacher--" %> 

但是,如果你想顯示在<li>標籤

<%= f.select :teacher_id, Teacher.all.map{|i| ["#{i.employee_no}, #{i.id}", "#{i.first_name},#{i.id}"]} , :prompt => "--Select a Teacher--" %> 
+0

是否有任何用於在rails中添加狀態的gem – user2310209

0

你在找這個嗎?

<%= f.select :teacher_id, Teacher.all.collect {|p| [ "#{p.employee_no} #{p.first_name}", p.id ]} , :prompt => "--Select a Teacher--" %>