我正在尝试选择特定记录但是在尝试保存时,employee_id
以空值保存,并且没有任何条件它正常工作,有没有办法解决这个问题?
<%= f.association :employee , collection:
Employee.where('student_advisor' => true).map(&:full_name) %>
答案 0 :(得分:2)
这对我有用:
<%= f.association :employee, :collection => Employee.where('student_advisor' => true), :label_method => :full_name, :value_method => :id %>
虽然恕我直言,但最好在您的控制器中设置该查询以保持逻辑不在您的视图中......
所以在控制器中:
@employee_list = Employee.where('student_advisor' => true)
在视图中:
<%= f.association :employee, :collection => @employee_list, :label_method => :full_name, :value_method => :id %>