1

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 .

Nilay Singh
  • 2,201
  • 6
  • 31
  • 61
  • Is recipient expecting an id or a user? That error looks like the type you are using is incorrect. – Kyle Bachan Aug 19 '15 at 21:11
  • I need to add the recipient id how can I add that here current_user is accessible but how can I use @feed = 2 – Nilay Singh Aug 19 '15 at 21:16
  • try @friend= User.find(2) and see if that works – Kyle Bachan Aug 19 '15 at 21:19
  • it worked why I can not use number 2 – Nilay Singh Aug 19 '15 at 21:22
  • Because number 2 doesn't mean anything on its own. Current_user isn't a number, it's a user object, that is why it works. I will post this as the correct answer then. Please accept this if this resolved the issue for you. – Kyle Bachan Aug 19 '15 at 21:26
  • I couldn't make it work using recipient_id... It does not make much sense to me, it should allow me to introduce the id instead of having to fetch the user. – hcarreras Oct 28 '15 at 09:36

1 Answers1

2

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.

Kyle Bachan
  • 1,053
  • 2
  • 15
  • 33
  • is there anything I can edit this thing in model or I have to do it like this – Nilay Singh Aug 19 '15 at 21:28
  • Possibly? I haven't really used the public activity gem. This might point you in the right direction, otherwise it sounds like you may need to post a new question. http://stackoverflow.com/questions/17131414/how-to-set-up-the-recipient-id-in-public-activity – Kyle Bachan Aug 19 '15 at 21:36