diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 018cdf2e6..5badac36e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -116,7 +116,7 @@ class UsersController < ApplicationController @user_forge_messages = @user.forge_messages.reverse @user_memo_messages = @user.memo_messages.reverse @user_course_messages_count = @user_course_messages.count - @user_forge_messages_count = @user_forum_messages.count + @user_forge_messages_count = @user_forge_messages.count @user_memo_messages_count = @user_memo_messages.count when 'homework' @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc") @@ -147,8 +147,8 @@ class UsersController < ApplicationController @user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Forum", @user).order("created_at desc") @user_forge_messages_count = @user_forge_messages.count when 'forum' - @user_forum_messages = Memo.where("memo_type =? and user_id =?", "Memo", @user).order("created_at desc") - @user_forum_messages_count = @user_forum_messages.count + @user_memo_messages = Memo.where("memo_type =? and user_id =?", "Memo", @user).order("created_at desc") + @user_memo_messages_count = @user_memo_messages.count else render_404 return diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index c9a511ccc..818bdaa74 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -207,19 +207,20 @@ class JournalsForMessage < ActiveRecord::Base if self.user_id != self.jour_id # 过滤自己给自己的留言消息 receivers << self.jour end - else # 回帖 - # 添加吧主 - if self.author_id != self.forum.creator_id - receivers << self.jour + else # 留言回复 + # 添加留言回复人 + if self.user_id != self.parent.user_id # 如果回帖人不是用户自己 + receivers << User.find(self.reply_id) end - # 添加发帖人 - if self.author_id != self.parent.author_id - receivers << self.parent.author + if self.user_id != self.parent.jour_id + receivers << self.parent.jour end end if self.jour_type == 'Principal' if self.user_id != self.jour_id - self.user_feedback_messages << UserFeedbackMessage.new(:user_id => self.jour_id, :user_message_id => self.id, :user_message_type => "Forum", :viewed => false) + receivers.each do |r| + self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false) + end end end end diff --git a/app/models/user_feedback_message.rb b/app/models/user_feedback_message.rb deleted file mode 100644 index 7cd8f5132..000000000 --- a/app/models/user_feedback_message.rb +++ /dev/null @@ -1,10 +0,0 @@ -class UserFeedbackMessage < ActiveRecord::Base - attr_accessible :user_id, :user_message_id, :user_message_type, :viewed - - belongs_to :user - belongs_to :journals_for_message - - validates :user_id,presence: true - validates :user_message_id,presence: true - validates :user_message_type, presence: true -end diff --git a/db/migrate/20150819072608_create_user_feedback_messages.rb b/db/migrate/20150820004659_create_user_feedback_messages.rb similarity index 71% rename from db/migrate/20150819072608_create_user_feedback_messages.rb rename to db/migrate/20150820004659_create_user_feedback_messages.rb index 382841c47..c5f5b85d9 100644 --- a/db/migrate/20150819072608_create_user_feedback_messages.rb +++ b/db/migrate/20150820004659_create_user_feedback_messages.rb @@ -2,8 +2,8 @@ class CreateUserFeedbackMessages < ActiveRecord::Migration def change create_table :user_feedback_messages do |t| t.integer :user_id - t.integer :user_message_id - t.string :user_message_type + t.integer :journals_for_message_id + t.string :journals_for_message_type t.integer :viewed t.timestamps diff --git a/db/schema.rb b/db/schema.rb index fd1d98e58..ea1c37968 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150819090720) do +ActiveRecord::Schema.define(:version => 20150820004659) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -572,16 +572,6 @@ ActiveRecord::Schema.define(:version => 20150819090720) do t.datetime "updated_at", :null => false end - create_table "forum_messages", :force => true do |t| - t.integer "user_id" - t.integer "forum_id" - t.integer "memo_id" - t.string "memo_type" - t.integer "viewed" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "forums", :force => true do |t| t.string "name", :null => false t.text "description" @@ -1436,11 +1426,11 @@ ActiveRecord::Schema.define(:version => 20150819090720) do create_table "user_feedback_messages", :force => true do |t| t.integer "user_id" - t.integer "user_message_id" - t.string "user_message_type" + t.integer "journals_for_message_id" + t.string "journals_for_message_type" t.integer "viewed" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "user_grades", :force => true do |t| diff --git a/spec/factories/user_feedback_messages.rb b/spec/factories/user_feedback_messages.rb deleted file mode 100644 index 945d6d8b3..000000000 --- a/spec/factories/user_feedback_messages.rb +++ /dev/null @@ -1,9 +0,0 @@ -FactoryGirl.define do - factory :user_feedback_message do - user_id 1 -user_message_id 1 -user_message_type "MyString" -viewed 1 - end - -end diff --git a/spec/models/user_feedback_message_spec.rb b/spec/models/user_feedback_message_spec.rb deleted file mode 100644 index 4ea61c36a..000000000 --- a/spec/models/user_feedback_message_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe UserFeedbackMessage, :type => :model do - pending "add some examples to (or delete) #{__FILE__}" -end