简体   繁体   中英

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.

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!

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