How to set up the recipient id in public activity

人走茶凉 提交于 2019-11-30 04:53:57

问题


I am going over Public Activity Gem Railscast Vid. (http://railscasts.com/episodes/406-public-activity)

My current DB looks/stores everything but the recipient_id....it shows up as 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">

I would like the recipient_id to be the user who the action is being performed on....

Ex.

If I like Tom's Post.....I would like Tom's ID to become the recipient_id & I'll be the owner_id.

I have currently set a recipient ID....using the code in my Likes Controller....but it only sets the recipient Id to current user....which is not what i want :(

LIKES CONTROLLER

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

Do I need to create a method or something. Please help.....new to rails


回答1:


tracked recipient: ->(controller, model) { model && model.user }

assuming Tom is the user of tracked object. Otherwise change model.user as per your application



来源:https://stackoverflow.com/questions/17131414/how-to-set-up-the-recipient-id-in-public-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!