0

我正在尝试选择特定记录,但是在尝试保存时,employee_id以空值保存,并且没有设置任何条件它可以正常工作,有什么办法可以解决这个问题吗?

<%= f.association :employee , collection:
Employee.where('student_advisor' => true).map(&:full_name) %>
4

1 回答 1

4

这对我有用:

<%= 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 %>
于 2013-10-09T04:31:53.190 回答