How to set recipient ID in public activity

I am going to engage in social activities with the Gem Railscast Vid. ( http://railscasts.com/episodes/406-public-activity )

My current DB looks / stores everything except recipient_id .... it displays 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 recipient_id to be the user whose action is being performed ...

Ref.

If I like Tom Post ..... I would like Tom ID to become the recipient of id, and I will be owner_id.

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

CONTROLLER LIKES

 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 

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

+6
source share
1 answer
 tracked recipient: ->(controller, model) { model && model.user } 

Assuming Tom is a user of a tracked object. Otherwise, modify model.user according to your application.

+11
source

Source: https://habr.com/ru/post/947395/


All Articles