留言按回复的更新时间排序

This commit is contained in:
cxt 2016-01-26 11:17:55 +08:00
parent 945d0a933f
commit 520811fdc7
5 changed files with 29 additions and 14 deletions

View File

@ -755,23 +755,17 @@ class UsersController < ApplicationController
if params[:type].present?
case params[:type]
when "public"
jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 0').order('created_on DESC')
@jour_count = jours.count
@jour = jours.limit(10).offset(@page * 10)
jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 0').order('updated_on DESC')
when "private"
jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 1').order('created_on DESC')
@jour_count = jours.count
@jour = jours.limit(10).offset(@page * 10)
jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 1').order('updated_on DESC')
else
jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@jour_count = jours.count
@jour = jours.limit(10).offset(@page * 10)
jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('updated_on DESC')
end
else
jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@jour_count = jours.count
@jour = jours.limit(10).offset(@page * 10)
jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('updated_on DESC')
end
@jour_count = jours.count
@jour = jours.limit(10).offset(@page * 10)
@type = params[:type]
if User.current == @user
jours.update_all(:is_readed => true, :status => false)

View File

@ -62,6 +62,7 @@ class WordsController < ApplicationController
update_forge_activity('JournalsForMessage',parent_id)
update_org_activity('JournalsForMessage',parent_id)
update_principal_activity('JournalsForMessage',parent_id)
(JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now)
end
respond_to do |format|
# format.html {

View File

@ -70,7 +70,7 @@ class JournalsForMessage < ActiveRecord::Base
validates :notes, presence: true, if: :is_homework_jour?
after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_at_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score
after_create :reset_counters!
after_update :update_ativity
#after_update :update_activity
after_destroy :reset_counters!
after_save :be_user_score
after_destroy :down_user_score

View File

@ -0,0 +1,20 @@
class UpdateJournalForMessage < ActiveRecord::Migration
def up
journals = JournalsForMessage.where("m_parent_id is null and jour_type ='Principal' ")
count = journals.count / 30 + 2
transaction do
for i in 1 ... count do i
journals.page(i).per(30).each do |jour|
act = UserActivity.where("act_type='JournalsForMessage' and act_id = #{jour.id}").first
unless act.nil?
jour.updated_on = act.updated_at
jour.save
end
end
end
end
end
def down
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160122143138) do
ActiveRecord::Schema.define(:version => 20160126024429) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false