ArgumentError: wrong number of arguments (0 for 1) rails 4
ArgumentError: wrong number of arguments (0 for 1) rails 4
在终端中:
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)
我在我的 application.I 中使用 paranoia
gem 想从 database.How 中销毁这条记录 我要销毁这条记录吗,请帮帮我。
您想查找单数 ServiceRequest
。因此,使用 find
:
而不是 where
sr = ServiceRequest.only_deleted.find(57)
或 find_by
如果您不希望它在找不到记录时引发错误:
sr = ServiceRequest.only_deleted.find_by(id: 57)
然后你可以在上面调用destroy
:
sr.destroy
但您似乎需要从 DB 中实际销毁对象,因为它已经被标记为 "destroyed",所以您应该使用:
sr.really_destroy!
在终端中:
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)
我在我的 application.I 中使用 paranoia
gem 想从 database.How 中销毁这条记录 我要销毁这条记录吗,请帮帮我。
您想查找单数 ServiceRequest
。因此,使用 find
:
where
sr = ServiceRequest.only_deleted.find(57)
或 find_by
如果您不希望它在找不到记录时引发错误:
sr = ServiceRequest.only_deleted.find_by(id: 57)
然后你可以在上面调用destroy
:
sr.destroy
但您似乎需要从 DB 中实际销毁对象,因为它已经被标记为 "destroyed",所以您应该使用:
sr.really_destroy!