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/>

我可以通过哪种方式做到这一点?谢谢大家

4

2 回答 2

0

你在找这个吗?

<%= f.select :teacher_id, Teacher.all.collect {|p| [ "#{p.employee_no} #{p.first_name}", p.id ]} , :prompt => "--Select a Teacher--" %>
于 2013-07-08T06:58:56.843 回答
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>标签中显示employee_no和id

<%= f.select :teacher_id, Teacher.all.map{|i| ["#{i.employee_no}, #{i.id}", "#{i.first_name},#{i.id}"]} , :prompt => "--Select a Teacher--" %>
于 2013-07-08T07:23:25.413 回答