socialforge/db/migrate/20150811080754_course_activ...

41 lines
1.5 KiB
Ruby

#encoding=UTF-8
class CourseActivities < ActiveRecord::Migration
def up
Course.all.each do |course|
transaction do
course.course_acts << CourseActivity.new(:user_id => course.tea_id,:course_id => course.id)
#作业
course.homework_commons.each do |homework_common|
homework_common.course_acts << CourseActivity.new(:user_id => homework_common.user_id,:course_id => course.id)
end
#通知
course.news.each do |new|
new.course_acts << CourseActivity.new(:user_id => new.author_id,:course_id => course.id)
end
#资源
course.attachments.each do |attachment|
attachment.course_acts << CourseActivity.new(:user_id => attachment.author_id,:course_id => course.id)
end
#讨论区
if course.boards.first
course.boards.first.messages.each do |message|
message.course_acts << CourseActivity.new(:user_id => message.author_id,:course_id => course.id)
end
end
#留言
course.journals_for_messages.each do |jour|
jour.course_acts << CourseActivity.new(:user_id => jour.user_id,:course_id => course.id)
end
#问卷
Poll.where("polls_type = 'Course' and polls_group_id = #{course.id}").each do |poll|
poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => course.id)
end
end
end
end
def down
# CourseActivity.destroy_all
end
end