在 Ruby on Rails 中显示模型的所有可用命名范围
特别是当您使用 Searchlogic 时。我很难猜测使用什么命名范围来实现我的需要。
Especially when you are using Searchlogic. It is kinda hard for me to guess what named scope to use to achieve what I need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以获取模型的所有定义的命名范围,使用
它为您提供一个散列,因此如果您只想要名称,请使用 Model.scopes.keys
但这只会为您提供已经定义的范围。它不会帮助您搜索逻辑生成的范围,因为,正如您可以在 文档< /a> (在引擎盖下),像
field_eq
等作用域仅在首次使用时创建:You can get all defined named scopes for a model, using
It gives you a hash, so if you want only names, use
Model.scopes.keys
But this will give you only scopes, that are already defined. It won't help you will scopes, generated by searchlogic, because, as you can read in documentation (Under the hood section), scopes like
field_eq
etc are created only when they are first used: