我正在使用PublicActivity gem創建新聞Feed。 香港專業教育學院已經有了它,並運行良好,但我想我的活動與另一個表關聯,以顯示更多細節添加或編輯寶石,但不編輯寶石
目前我的新聞提要只是說「發佈一個微柱」的時候,有人發出後 我想要的新聞提要顯示已發佈的MicroPost。 我編輯的寶石文件,包括關聯,這樣的活動看起來在微柱表,以獲得微柱
module PublicActivity
module ORM
module ActiveRecord
# The ActiveRecord model containing
# details about recorded activity.
class Activity < ::ActiveRecord::Base
include Renderable
belongs_to :trackable, :polymorphic => true
belongs_to :owner, :polymorphic => true
belongs_to :recipient, :polymorphic => true
serialize :parameters, Hash
# I added this
has_one :micropost, foreign_key: "id", primary_key: "trackable_id"
end
end
end
end
這似乎這樣的伎倆,並顯示用戶發佈,除了我想這樣做的微柱無需編輯寶石。我嘗試了許多不同的方式來修補它,但似乎無法解決它。有人能幫助我嗎?
在此先感謝
下面是我的一些代碼
控制器
class ActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc").where(owner_id: [current_user.followed_user_ids, current_user], owner_type: "User")
end
end
視圖
<h1>Activities</h1>
<% @activities.each do |activity| if activity.trackable %>
<div class="activity">
<%= render_activity activity %>
</div>
<% end %>
<% end %>
活動微柱
<% if activity.trackable %>
<%= link_to gravatar_for(activity.owner), activity.owner %>
<span class="user">
<%= link_to activity.owner.name, activity.owner %>
</span>
<span class="content">
Created a Micropost
# <%= activity.micropost.content %> COMMENTED OUT WHILE NOT WORKING
</span>
<span class="timestamp">
<%= time_ago_in_words(activity.created_at) %> ago.
</span>
<% end %>
編輯
而且當我更新了寶石從作者GitHub的當前,即使編輯寶石不起作用。正因爲如此我還沒有能剛剛從他的寶石叉子和克隆它
你有沒有嘗試把猴子補丁放入初始化程序中?將它放在/ lib或/ extras中將不起作用。 – RobHeaton
你能告訴我該放什麼嗎? –