【发布时间】:2021-01-13 10:33:00
【问题描述】:
我正在开发一个使用 ActiveAdmin 的 ROR 应用程序。我正在尝试使用批处理操作删除用户。它显示了成功的消息,但实际上它并没有从数据库(postgres)中删除用户。
这是批处理操作的代码-
batch_action :destroy, :confirm => "Are you sure you want to delete the user?", do |ids|
Application::RecordsDestroy.perform_async Application::User, ids
redirect_to user_path, :notice => "User is deleted"
end
这是记录销毁文件的代码-
class RecordsDestroy
include Sidekiq::App
def perform(res_model, ids)
records = res_model.constantize.where(id: ids).destroy_all
Rails.logger.info "Records for model #{res_model} have been premanently deleted"
end
end
谁能告诉我代码有什么问题?为什么它不起作用?
任何形式的帮助都将不胜感激。
【问题讨论】:
-
您指的是哪个“成功”消息? “用户已被删除”或“模型 #{res_model} 的记录已被预先删除”?如果您没有看到“xxx 的记录”,则可能是后台作业没有排入 Redis。
-
@Ali 我收到的成功消息是“用户被删除”。
-
尝试在 Rails 控制台中运行您的后台作业,并查看 Sidekiq 日志中是否记录了“模型 xxx 的记录”。
标签: ruby-on-rails postgresql activeadmin record destroy