Rails4范围与参数(Rails4 scope with parameters)

编程入门 行业动态 更新时间:2024-10-23 17:25:28
Rails4范围与参数(Rails4 scope with parameters)

我不知何故在rails文档中找不到有关如何将某些参数放入命名范围的任何地方,像这样的东西

范围:by_id, - > {where:id = id}

I somehow cannot find any place in the rails documentation about how to put some params into a named scope, f.e. something like this

scope :by_id, -> { where :id = id }

最满意答案

scope :by_id, ->(id) {where (:id => id)}

这应该工作

scope :by_id, ->(id) {where (:id => id)}

this should work

更多推荐

本文发布于:2023-08-03 15:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   parameters   scope

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!