简体   繁体   中英

Ruby on Rails: User not deleting from the postgres database

I'm working on a ROR application which uses ActiveAdmin. I'm trying to delete a user using batch action. It is showing the message of success but in actual it is not deleting the user from database (postgres).

Here is the code of batch action -

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

This is the code of Records Destroy file -

  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

Can anyone tell me what's wrong with code? Why it isn't working?

Any kind of help would be greately appreciated.

Can you try

Application::RecordsDestroy.perform_async('Application::User', ids)

Since you're using constantize, I think your job expects string as parameter.

Also you can check your sidekiq logs for error

This appears to be a classic mistake when using Sidekiq. See best practices on job parameters.

You must not pass an AR model or complex object directly, as this will not be serialized correctly by Sidekiq. Instead, you must pass a primitive, such as a string:

Application::RecordsDestroy.perform_async 'Application::User', ids

Related tip on debugging Sidekiq: Add

require 'sidekiq/testing'
Sidekiq::Testing.inline!

to your application initialization (eg development.rb ), which will make your jobs run synchronously in you main process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM