在Simple Form Association中指定值
我正在尝试选择特定记录但是在尝试保存时, employee_id
以空值保存,并且没有任何条件它正常工作,有什么方法可以解决这个问题吗?
true).map(&:full_name) %>
这对我有用:
<%= 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 %>