【发布时间】:2018-08-09 03:41:06
【问题描述】:
我的应用需要销毁所有成员少于两个的团队。
这种方法似乎有效,但我希望尽可能将其“rubify”到一行。
@consultancy.teams.reverse.each do |team|
team.destroy if team.users.count < 2
end
我正在尝试做类似以下的事情,但我收到了拒绝错误!方法。
@consultancy.teams.reject!{|x| x.users.count < 2}
NoMethodError: undefined method `reject!' for #<Team::ActiveRecord_Associations_CollectionProxy:0x00000003f72850>
.delete_all 也会抛出错误。
@consultancy.teams.select{|x| x.users.count < 2}.delete_all
NoMethodError: undefined method `delete_all' for #<Array:0x0000000b72dcf0>
提前感谢您的任何见解。
【问题讨论】:
-
reject和delete_all出现什么错误? -
好点。我编辑了问题以包含错误消息。
-
这个问题应该有助于解决这个问题:stackoverflow.com/questions/31409792/… 基本上,
@consultancy.teams不是一个数组
标签: ruby