如何在公共活动中设置收件人ID [英] How to set up the recipient id in public activity

查看:222
本文介绍了如何在公共活动中设置收件人ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过公共活动Gem Railscast Vid。 ( http://railscasts.com/episodes/406-public-activity

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

我目前的数据库看起来/存储所有内容,但是recipient_id ....它显示为nil

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">

我想让recipient_id成为执行操作的用户....

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

例如

如果我喜欢 Tom's Post .....我会像Tom's ID一样成为recipient_id&我将成为owner_id。

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

我目前已设置收件人ID ....使用我的Likes Controller中的代码....但它只设置收件人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

我需要创建一个方法或其他东西。 ... new to rails

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

推荐答案

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

否则,根据您的应用程序更改 model.user

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

这篇关于如何在公共活动中设置收件人ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆