Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up the recipient id in public activity

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

like image 493
Serge Pedroza Avatar asked Jun 16 '13 08:06

Serge Pedroza


1 Answers

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

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

like image 51
Muntasim Avatar answered Nov 19 '22 19:11

Muntasim