【发布时间】:2018-01-07 07:01:52
【问题描述】:
我发现这篇关于清理链式作用域的文章在我正在从事的项目中非常有用。但是,我的一些范围有参数。我想不出一种方法来使这个工作与争论。我尝试了字符串插值,我怀疑它不起作用,当然,没有。
https://www.sitepoint.com/dynamically-chain-scopes-to-clean-up-large-sql-queries/
def self.send_chain(methods)
methods.inject(self, :send)
end
$ methods = ["with_author", "pending_review", "draft", "flagged", "published", "with_website", "with_meta_title", "with_meta_description"]
$ Article.send_chain(methods)
【问题讨论】: