如何在公共活动中设置收件人ID

Sur*_*oza 6 ruby gem ruby-on-rails railscasts ruby-on-rails-3

我正在浏览Public Activity Gem Railscast Vid.(http://railscasts.com/episodes/406-public-activity)

我当前的数据库查找/存储除recipient_id之外的所有内容....它显示为nil

#<PublicActivity::Activity id: 108, trackable_id: 133, trackable_type: "Relationship",
owner_id: 1, owner_type: "User", key: "relationship.create", parameters: {}, 
recipient_id: nil, recipient_type: nil, created_at: "2013-06-16 07:37:28", 
updated_at: "2013-06-16 07:37:28">
Run Code Online (Sandbox Code Playgroud)

我希望recipient_id成为正在执行操作的用户....

防爆.

如果我喜欢Tom's Post .....我希望Tom的ID成为recipient_id我将成为owner_id.

我目前设置了一个收件人ID ....使用我的喜欢控制器中的代码....但它只将收件人ID设置为当前用户....这不是我想要的:(

喜欢控制器

class Like < ActiveRecord::Base
  include PublicActivity::Model
  tracked except: :destroy, owner: ->(controller, model) { controller && controller.current_user }

  **tracked except: :destroy, recipient: ->(controller, model) { controller && controller.current_user }**

  attr_accessible :dailypost_id, :user_id

  belongs_to :user
  belongs_to :dailypost


  default_scope order: 'likes.created_at DESC'
end
Run Code Online (Sandbox Code Playgroud)

我是否需要创建方法或其他东西.请帮助.....新的铁路

Mun*_*sim 11

tracked recipient: ->(controller, model) { model && model.user }
Run Code Online (Sandbox Code Playgroud)

假设Tom是跟踪对象的用户.否则model.user根据您的申请进行更改