ruby-on-railspublic-activity

Rails Public_Activity gem recipient id getting error


I am using a gem called Public_Activity I am trying to add a recipient whenever someone create the comment for that I am using this code :

@comment.create_activity :create, recipient: @friend, owner: current_user

wehre @freind = 2 or whatever when I am using this I am getting this error :

NoMethodError (undefined method `primary_key' for Fixnum:Class):

When I am using this code :

@comment.create_activity :create, recipient: current_user, owner: current_user

It works perfect I need to update the recipient with some other user how can I do this any help .


Solution

  • Recipient is looking for a user and not an id. The reason why current_user works is because it is a user object. If you had used current_user.id, it would not have worked.

    Use User.find(2) to get the user object.