ruby-on-railsacts-as-paranoid

ArgumentError: wrong number of arguments (0 for 1) rails 4


In terminal:

2.2.0 :001 > sr=ServiceRequest.only_deleted.where(:id=>57)

=> #<ActiveRecord::Relation [#<ServiceRequest id: 57, sr_number: "SRN57", email: "xxx@gmail.com", phone: "54545121", subject: "change of address", body: "sdssssssssssssss", status_id: 1, request_type_id: 1, customer_id: nil, created_at: "2015-04-24 13:06:52", updated_at: "2015-04-28 05:13:05", deleted_at: "2015-04-28 05:13:05">]> 2.2.0 :004 > sr.destroy

ArgumentError: wrong number of arguments (0 for 1) I am using paranoia gem in my application.I want to destroy this record from the database.How do i destroy this record, please help me out.


Solution

  • You want to find singular ServiceRequest. So, instead of where, use find:

    sr = ServiceRequest.only_deleted.find(57)
    

    or find_by if you don't want it to raise an error if the record isn't found:

    sr = ServiceRequest.only_deleted.find_by(id: 57)
    

    then you can call destroy on it:

    sr.destroy
    

    But it seems you need to actually destroy object from DB, since it's already marked as "destroyed", so you should rather use:

    sr.really_destroy!