Ruby on rails Rails:基于列销毁除最新之外的所有内容
我有一个Ruby on rails Rails:基于列销毁除最新之外的所有内容,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我有一个授权模型,里面有过期的副本。我想根据授权中的:provider列删除除最新之外的所有内容,留下最新的“linkedin”授权、最新的“facebook”等 我将如何编写该方法?逻辑上是这样的,但它给出了这个错误(TypeError:无法将授权转换为数组(authorization\to\u-class)): 也许这个: last_record = Authorisation.where(provider: 'facebook').last Authorisation.where('c
授权
模型,里面有过期的副本。我想根据授权
中的:provider
列删除除最新之外的所有内容,留下最新的“linkedin”
授权、最新的“facebook”
等
我将如何编写该方法?逻辑上是这样的,但它给出了这个错误(TypeError:无法将授权转换为数组(authorization\to\u-class)
):
也许这个:
last_record = Authorisation.where(provider: 'facebook').last
Authorisation.where('created_at < ?', last_record.created_at).delete_all
但我认为它只适用于Rails4
更新
这样更好:
Authorisation.where('id != ?', Authorisation.last.id).delete_all
Authorisation.where.not(id: Authorisation.last.id).delete_all
Authorisation.where('id != ?', Authorisation.last.id).delete_all