UsersController 中的 ArgumentError#remove 错误数量的参数(给定 3,预期为 2)
可以在教室中添加和删除用户类型的教师。当他们被添加时,他们会收到通知。当他们被移除时,他们会收到通知。除了,当删除它们时,我得到一个错误。
UsersController 中的 ArgumentError#remove 错误数量的参数(给定 3,预期为 2)行:def remove_teacher_notification(课堂,老师)
现在我想我知道为什么会发生这种情况了,它检测到所有课堂教师都是教师,而不仅仅是被撤职的教师。所以,因为一个班有两个老师,所以给出了 3 个参数。
这是我的代码:用户控制器
def remove
## Find the join table where the teacher and classroom match
join_table = ClassroomTeacher.where(teacher_id: @teacher, classroom_id: @classroom)
## If so, remove the teacher from the classroom by deleting the join table
## This will remove the association between the teacher and the classroom
if join_table
@teacher.classroom_teachers.delete(join_table)
remove_teacher_notification @classroom, @teacher, notice: "Notification sent"
redirect_to classroom_path(@classroom), notice: 'Teacher was successfully removed.'
end
end
def remove_teacher_notification(classroom, teacher)
Notification.create(user_id: teacher.id,
notified_by_id: current_user.id,
identifier: classroom.id,
notice_type: 'remove')
end
它可以成功删除教师,但不会正确创建通知。不太清楚如何定义教师。谢谢。
您remove_teacher_notification
使用 3 个参数进行调用,但方法定义指出它需要 2 个。
@classroom
是第一个 arg,@teacher
第二个,notice: "Notification sent"
hash 是第三个。从我看到的第三个是不打算使用的,所以可能你不小心把它放在那里。
或者它应该以Notification.create
相同的方式传递给notice_type
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句