为什么我不应该使用 ransack 来简化查询生成?
我在 ransack README 的开头发现了这个声明。
如果您正在寻找能够简化模型或控制器层查询生成的工具,那么您可能不需要 Ransack。
我仅使用 Rails 作为 API,但我仍然想使用 ransack 而不是自己处理查询生成(范围、控制器中的额外代码等),是否有理由不仅使用 ransack 而不使用它的视图部分?
如果是,那么什么更适合我的需要?
提前致谢。
I found this statement right at the beginning of ransack README.
If you're looking for something that simplifies query generation at the model or controller layer, you're probably not looking for Ransack.
I'm using rails as an API only, but I still would like to use ransack instead of handling the query generation by myself (scopes, extra code in the controller, etc), are there reasons not to use ransack only for that without using the view part of it?
If yes then what better suits my need?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Ransack 实际上是一个用于将键值对(例如
name_eq: 'ransack'
)转换为 ActiveRecord 子句(例如where(name: 'ransack')
)的工具。在后端,您不妨编写 ActiveRecord 子句。
话虽如此,如果您仅使用 Rails 作为 API,并不意味着 Ransack 没有用处。我们使用它来处理指定搜索的 GraphQL 查询参数,这非常有用。
Ransack is really a tool for converting key-value pairs, like
name_eq: 'ransack'
into an ActiveRecord clause likewhere(name: 'ransack')
.In the back end, you might as well write the ActiveRecord clause.
Having said that, if you are using Rails as an API only that doesn't mean there is no use for Ransack. We use it to process GraphQL query arguments that specify searches, and it's great for that.