diff --git a/app/models/poll.rb b/app/models/poll.rb index b0499b572..d2f5b40fe 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -44,7 +44,9 @@ class Poll < ActiveRecord::Base def act_as_course_activity if self.polls_type == "Course" if self.polls_status == 2 #问卷是发布状态 - self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.polls_group_id) + if CourseActivity.where(:course_id => self.polls_group_id, :user_id => self.user_id, :course_act_id => self.id, :course_act_type => 'Poll').count == 0 + self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.polls_group_id) + end elsif self.polls_status == 1 #问卷是新建状态 self.course_acts.destroy_all end diff --git a/db/migrate/20161216031906_delete_course_activities.rb b/db/migrate/20161216031906_delete_course_activities.rb new file mode 100644 index 000000000..dbbe193ce --- /dev/null +++ b/db/migrate/20161216031906_delete_course_activities.rb @@ -0,0 +1,14 @@ +class DeleteCourseActivities < ActiveRecord::Migration + def up + course_acts = CourseActivity.where(:course_id => 844, :user_id => 10096, :course_act_id => 436, :course_act_type => 'Poll') + + if course_acts.count > 1 + course_acts.limit(course_acts.count - 1).each do |act| + act.delete + end + end + end + + def down + end +end