如何使用 Rails 代码生成
ActiveAdmin
评论?
假设您有一个
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