消息查询代码优化

This commit is contained in:
huang 2015-08-17 15:04:09 +08:00
parent fda8c802fb
commit fe077a27fb
1 changed files with 4 additions and 5 deletions

View File

@ -114,14 +114,13 @@ class UsersController < ApplicationController
else
case params[:type]
when 'homework'
@user_course_messages = @user.course_messages.reverse.select{|x| x.course_message_type == "HomeworkCommon"}
#@user_course_messages = ForgeMessage.find_by_sql("select * from course_messages where user_id='#{@user.id}' and course_message_type = 'HomeworkCommon' order by created_at desc;")
@user_course_messages = CourseMessage.where(:course_message_type => "HomeworkCommon", :user_id => @user)
when 'message'
@user_course_messages = @user.course_messages.reverse.select{|x| x.course_message_type == "Message"}
@user_course_messages = CourseMessage.where(:course_message_type => "Message", :user_id => @user)
when 'news'
@user_course_messages = @user.course_messages.reverse.select{|x| x.course_message_type == "News"}
@user_course_messages = CourseMessage.where(:course_message_type => "News", :user_id => @user)
when 'poll'
@user_course_messages = @user.course_messages.reverse.select{|x| x.course_message_type == "Poll"}
@user_course_messages = CourseMessage.where(:course_message_type => "Poll", :user_id => @user)
end
end
respond_to do |format|