在操作过程中生成活跃的管理员评论[关闭]

问题描述 投票:0回答:1

如何使用 Rails 代码生成

ActiveAdmin
评论?

ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-5 activeadmin
1个回答
3
投票

假设您有一个

User
模型,并且您想为特定用户创建评论。

在模型中:

after_update :add_comment

 def add_comment 
  ActiveAdmin::Comment.create(
    resource_id: User.last.id, # id of that particular user to which you add comment
    namespace: 'admin',
    body: 'Your comment body',
    resource_type: 'User',
    author_id: 1, # id of the comment's author, could be AdminUser.first, for example
    author_type: 'AdminUser'
  )
end
© www.soinside.com 2019 - 2024. All rights reserved.