Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法“shuffle';对于true:TrueClass_Ruby On Rails - Fatal编程技术网

Ruby on rails 未定义的方法“shuffle';对于true:TrueClass

Ruby on rails 未定义的方法“shuffle';对于true:TrueClass,ruby-on-rails,Ruby On Rails,类似的用户随机顺序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(:sta

类似的用户随机顺序
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

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

实际上,您可以使用
next
从块返回值,但这里不需要


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

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

实际上,您可以使用
next
从块返回值,但这里不需要


另外,请使用版本控制系统,以便在需要时恢复到工作代码。

谢谢!这正是问题所在。谢谢!这正是问题所在。