undefined方法`shuffle'表示true:TrueClass(undefined method `shuffle' for true:TrueClass)

编程入门 行业动态 更新时间:2024-10-28 00:19:11
undefined方法`shuffle'表示true:TrueClass(undefined method `shuffle' for true:TrueClass)

类似的用户随机顺序shuffle不再从控制器工作。 有人可以帮我处理代码吗?

用户模型:

def similar arr = User.where(:gender => self.gender).where.not(:id => self.id) arr.select{ |c| if !c.location.nil? return c.location.state == self.location.try(:state) else return false end } end

The similar user random order shuffle is no longer working from the controller. Can someone assist me with the code?

User model:

def similar arr = User.where(:gender => self.gender).where.not(:id => self.id) arr.select{ |c| if !c.location.nil? return c.location.state == self.location.try(:state) else return false end } end

最满意答案

您应该尝试从similar的单词中删除单词return的实例。 那些返回语句导致similar返回true或false而不是返回数组。

您实际上可以使用next来返回块中的值,但这里不需要它。

此外,使用版本控制系统,以便在需要时可以恢复为工作代码。

You should try removing the instances of the word return from similar. Those return statements cause similar to return true or false instead of returning an array.

You can actually use next to return values from a block but it's not needed here.

Also, use a version control system so you can revert back to working code when needed.

更多推荐

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

发布评论

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

>www.elefans.com

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