班级测验发布时发送消息通知

This commit is contained in:
cxt 2017-03-24 20:45:11 +08:00
parent b6bf0aafb1
commit 69690d57a4
1 changed files with 7 additions and 6 deletions

View File

@ -14,7 +14,9 @@ class ExerciseController < ApplicationController
exercise.update_column('exercise_status', 2) exercise.update_column('exercise_status', 2)
course = exercise.course course = exercise.course
course.members.each do |m| course.members.each do |m|
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) if m.user_id != exercise.user_id
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
end
end end
end end
@ -41,8 +43,10 @@ class ExerciseController < ApplicationController
publish_exercises.each do |exercise| publish_exercises.each do |exercise|
exercise.update_column('exercise_status', 2) exercise.update_column('exercise_status', 2)
course = exercise.course course = exercise.course
course.members.each do |m| if m.user_id != exercise.user_id
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) course.members.each do |m|
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
end
end end
end end
@ -441,9 +445,6 @@ class ExerciseController < ApplicationController
@exercise.exercise_status = 2 @exercise.exercise_status = 2
@exercise.publish_time = Time.now @exercise.publish_time = Time.now
if @exercise.save if @exercise.save
@exercise.course.members.each do |m|
@exercise.course_messages << CourseMessage.create(:user_id =>m.user_id, :course_id => @exercise.course.id, :viewed => false,:status=>2)
end
#redirect_to exercise_index_url(:course_id=> @course.id) #redirect_to exercise_index_url(:course_id=> @course.id)
respond_to do |format| respond_to do |format|
format.js format.js