我有一个 Collection_select,其中 Multiple 设置为 true
#views/courses/new
<%=collection_select(:course, :department_id, Department.all, :id, :name, {},
:multiple =>true,:size => 8,:class=> "text")%>
在我的模型中
#deparment Model
has_many :courses
#Course Model
belongs_to :deparment
我想要一种情况,如果一门课程从多选列表中选择了多个部门,则此详细信息将保存在课程表中。My Current Implementation 仅保存课程的第一个选定部门,并丢弃其余部门。请我如何实现这一点。
def create
@course = Course.new(params[:course] || [])
if @course.save
redirect_to courses_path, :notice => "Course Created Successfully"
else
redirect_to new_course_path
flash[:alert] = "Error Creating Course"
end
end
谢谢你