Ruby on rails RubyonRails:用户未从postgres数据库中删除

Ruby on rails RubyonRails:用户未从postgres数据库中删除,ruby-on-rails,postgresql,activeadmin,record,destroy,Ruby On Rails,Postgresql,Activeadmin,Record,Destroy,我正在开发一个使用ActiveAdmin的ROR应用程序。我正在尝试使用批处理操作删除用户。它显示了成功的消息,但实际上并不是从数据库(postgres)中删除用户 这是批处理操作的代码- batch_action :destroy, :confirm => "Are you sure you want to delete the user?", do |ids| Application::RecordsDestroy.perform_async Applicat

我正在开发一个使用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

谁能告诉我代码有什么问题吗?为什么它不起作用

任何形式的帮助都将不胜感激。

你能试试吗

Application::RecordsDestroy.perform_async('Application::User', ids)
因为您使用的是constantize,所以我认为您的工作需要字符串作为参数


您还可以检查sidekiq日志中的错误

这似乎是使用sidekiq时的一个典型错误。请参阅作业参数

您不能直接传递AR模型或复杂对象,因为Sidekiq无法正确序列化。相反,您必须传递一个基元,例如字符串:

Application::recordsdestory.perform\u async'Application::User',id
调试Sidekiq的相关提示:添加

要求“侧击/测试”
Sidekiq::Testing.inline!

应用程序初始化(例如,
development.rb
),这将使您的作业在主进程中同步运行。

您指的是哪条“成功”消息?“用户已删除”或“模型#{res_model}的记录已被临时删除”?如果您没有看到“xxx的记录”,则可能是后台作业没有排队到Redis。@Ali我收到的成功消息是“用户已被删除”。请尝试在Rails控制台中运行您的后台作业,并查看Sidekiq日志中是否记录了“型号xxx的记录”。很抱歉,它不起作用。