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 } endThe 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.
更多推荐
发布评论