From b5f4b1dd96f09eb87aa110b9b5fc9143064f30c0 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 17 Sep 2015 13:58:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9A24=E5=B0=8F=E6=97=B6?= =?UTF-8?q?=E5=86=85=E7=B3=BB=E7=BB=9F=E6=B6=88=E6=81=AF=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6669a43d7..748967990 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -107,17 +107,18 @@ class UsersController < ApplicationController end # 记录当前点击按钮的时间 # 考虑到用户未退出刷新消息页面 - if OnclickTime.where("user_id =?", User.current).first.nil? + message_time = OnclickTime.where("user_id =?", User.current).first + if message_time.nil? message_new_time = OnclickTime.new message_new_time.user_id = User.current.id message_new_time.onclick_time = Time.now message_new_time.save else - message_new_time = OnclickTime.where("user_id =?", User.current).first - message_last_time = message_new_time.onclick_time - message_new_time.update_attributes(:onclick_time => Time.now) + # 24小时内显示 + contrast_time = Time.now - 86400 + message_time.update_attributes(:onclick_time => Time.now) end - @user_system_messages = SystemMessage.where("created_at >?", message_last_time).order("created_at desc") + @user_system_messages = SystemMessage.where("created_at >?", contrast_time).order("created_at desc") # 当前用户查看消息,则设置消息为已读 if params[:viewed] == "all" course_querys = @user.course_messages