Rails 中,如何在 Post/Patch 表单中创建关联关系?
答案是使用 collection_singular_ids
Controller:
def create
Student.new(student_params)
end
def update
@student.update(student_params)
end
private
def student_params
params.require(:student).permit(lesson_ids: [])
end
约定优于配置 ❤