我的Article
模型有recent
,compiled
,featured
范围。我可以像这样链接这些范围:
Article.recent.compiled.featured
现在我有一系列这些范围:
scopes = [:recent, :compiled, :featured]
or
scopes = [:recent, :compiled]
我事先并不知道scopes
变量中有多少个范围。我只知道它是一系列范围。
如何将此数组用作Article
模型上要调用的范围链?如上所述?
答案 0 :(得分:3)
只需使用注入:
scopes.inject(Article){ |ar,scope| ar.send(scope) }