消息公共表
This commit is contained in:
parent
f26ccac3b9
commit
d575ce5e5f
|
@ -13,8 +13,24 @@ class ForgeMessage < ActiveRecord::Base
|
|||
belongs_to :forge_message ,:polymorphic => true
|
||||
belongs_to :project
|
||||
belongs_to :user
|
||||
has_many :message_alls, :class_name => 'MessageAll',:as =>:message
|
||||
validates :user_id,presence: true
|
||||
validates :project_id,presence: true
|
||||
validates :forge_message_id,presence: true
|
||||
validates :forge_message_type, presence: true
|
||||
after_save :add_user_activity
|
||||
|
||||
def add_user_activity
|
||||
message_all = MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first
|
||||
if message_all
|
||||
message_all.save
|
||||
else
|
||||
message_all = MessageAll.new
|
||||
message_all.message_id = self.id
|
||||
message_all.message_type = self.class.to_s
|
||||
message_all.container_type = "Project"
|
||||
message_all.container_id = self.project_id
|
||||
message_all.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
class MessageAll < ActiveRecord::Base
|
||||
attr_accessible :container_id, :container_type, :message_id, :message_type
|
||||
# 虚拟关联---项目消息表/课程消息表/用户留言消息表/贴吧消息表
|
||||
belongs_to :message ,:polymorphic => true
|
||||
# 虚拟关联---项目/课程
|
||||
belongs_to :container ,:polymorphic => true
|
||||
end
|
|
@ -29,7 +29,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<% if params[:type] == nil? %>
|
||||
<% if params[:type].nil? %>
|
||||
<div class="newsReadSetting">
|
||||
有 <span class="c_red">8</span> 封未读<a href="javascript:void(0);" class="ml15">全部设为已读</a>
|
||||
</div>
|
||||
|
@ -219,7 +219,7 @@
|
|||
<li class="homepageNewsPublisher fl">
|
||||
<%=link_to urm.memo.author, user_path(urm.memo.author), :class => "newsBlue" %>
|
||||
</li>
|
||||
<li class="homepageNewsType fl" >新建贴吧帖子</li>
|
||||
<li class="homepageNewsType fl" ><%= urm.memo.parent_id.nil? ? "新建贴吧帖子" : "回复贴吧帖子" %></li>
|
||||
<li class="homepageNewsContent fl"><a href="javascript:void(0);" class="newsGrey">
|
||||
<%= link_to urm.memo.content.html_safe, forum_memo_path(urm.memo.forum_id, urm.memo.parent_id ? urm.memo.parent_id: urm.memo.id),:class => "newsGrey" , :title => "#{urm.memo.content.html_safe}" %></a>
|
||||
</li>
|
||||
|
@ -241,7 +241,7 @@
|
|||
</li>
|
||||
<li class="homepageNewsType fl"><%= ufm.journals_for_message.reply_id == 0 ? "给你留言了" : "回复了你的留言" %></li>
|
||||
<li class="homepageNewsContent fl"><a href="javascript:void(0);" class="newsGrey">
|
||||
<%= link_to ufm.journals_for_message.notes.html_safe, feedback_path(ufm.journals_for_message.jour_id), :class => "newsGrey", :title => "#{ufm.journals_for_message.notes.html_safe}" %></a>
|
||||
<%= link_to ufm.journals_for_message.notes.html_safe, feedback_path(ufm.journals_for_message.jour_id), :class => "newsGrey", :title => "#{ufm.journals_for_message.notes}".html_safe %></a>
|
||||
</li>
|
||||
<li class="homepageNewsTime fl"><%= time_tag(ufm.journals_for_message.created_on).html_safe %> </li>
|
||||
</ul>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
class CreateMessageAlls < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :message_alls do |t|
|
||||
t.string :message_type
|
||||
t.integer :message_id
|
||||
t.string :container_type
|
||||
t.integer :container_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
FactoryGirl.define do
|
||||
factory :message_all do
|
||||
message_type "MyString"
|
||||
message_id 1
|
||||
container_type "MyString"
|
||||
container_id 1
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe MessageAll, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue