diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 900af0e77..0058e6e4c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -627,14 +627,15 @@ class UsersController < ApplicationController end def show + @page = params[:page] ? params[:page].to_i + 1 : 0 - @type = params[:type] + user_project_ids = @user.projects.visible.empty? ? "(-1)" : "(" + @user.projects.visible.map{|project| project.id}.join(",") + ")" user_course_ids = @user.courses.visible.empty? ? "(-1)" : "(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" course_types = "('Message','News','HomeworkCommon','poll')" project_types = "('Message','Issue')" - if @type - case @type + if params[:type].present? + case params[:type] when "course_homework" @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('created_at desc').limit(10).offset(@page * 10) when "course_news" @@ -654,6 +655,7 @@ class UsersController < ApplicationController @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids}) and act_type in #{course_types}").order('created_at desc').limit(10).offset(@page * 10) end # @user_activities = paginateHelper @user_activities,500 + @type = params[:type] respond_to do |format| format.js format.html {render :layout => 'new_base_user'} diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index 1d0920c1c..284687870 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -10,7 +10,7 @@ class CourseActivity < ActiveRecord::Base #在个人动态里面增加当前动态 def add_user_activity - user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'").first + user_activity = UserActivity.where("act_type = '#{self.course_act_type.to_s}' and act_id = '#{self.course_act_id}'").first if user_activity user_activity.save else @@ -24,7 +24,7 @@ class CourseActivity < ActiveRecord::Base end def destroy_user_activity - user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'") + user_activity = UserActivity.where("act_type = '#{self.course_act_type.to_s}' and act_id = '#{self.course_act_id}'") user_activity.destroy_all end end diff --git a/app/models/forge_activity.rb b/app/models/forge_activity.rb index b7fc5e4c2..9bc10bebf 100644 --- a/app/models/forge_activity.rb +++ b/app/models/forge_activity.rb @@ -25,7 +25,7 @@ class ForgeActivity < ActiveRecord::Base #在个人动态里面增加当前动态 def add_user_activity - user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'").first + user_activity = UserActivity.where("act_type = '#{self.forge_act_type.to_s}' and act_id = '#{self.forge_act_id}'").first if user_activity user_activity.save else @@ -39,7 +39,7 @@ class ForgeActivity < ActiveRecord::Base end def destroy_user_activity - user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'") + user_activity = UserActivity.where("act_type = '#{self.forge_act_type.to_s}' and act_id = '#{self.forge_act_id}'") user_activity.destroy_all end end diff --git a/app/views/courses/_history.html.erb b/app/views/courses/_history.html.erb index 864509546..70e943e99 100644 --- a/app/views/courses/_history.html.erb +++ b/app/views/courses/_history.html.erb @@ -5,7 +5,7 @@