0
我目前正在關注從頭集407 活動飼料瑞安貝茨教程,我想知道如何才能顯示我的朋友的活動只。如何顯示用戶的公共活動只有朋友在Rails 4
如果使用的是公共活動的寶石,當我這樣做
@activities = PublicActivity::Activity.order("created_at desc").*where(owner_id: current_user.friend_ids, owner_type: "User")*
,併爲這個表是即寶石
class CreateActivities < ActiveRecord::Migration
# Create table
def self.up
create_table :activities do |t|
t.belongs_to :trackable, :polymorphic => true
t.belongs_to :owner, :polymorphic => true
t.string :key
t.text :parameters
t.belongs_to :recipient, :polymorphic => true
t.timestamps
end
add_index :activities, [:trackable_id, :trackable_type]
add_index :activities, [:owner_id, :owner_type]
add_index :activities, [:recipient_id, :recipient_type]
end
# Drop table
def self.down
drop_table :activities
end
end
而從頭開始實現這個表是這樣的
class CreateActivities < ActiveRecord::Migration
def change
create_table :activities do |t|
t.belongs_to :user
t.string :action
t.belongs_to :trackable
t.string :trackable_type
t.timestamps
end
add_index :activities, :user_id
add_index :activities, :trackable_id
end
end
如何向用戶朋友顯示此活動?