Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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 闭包树gem:NoMethodError:undefined方法“[]=';零级:零级_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 闭包树gem:NoMethodError:undefined方法“[]=';零级:零级

Ruby on rails 闭包树gem:NoMethodError:undefined方法“[]=';零级:零级,ruby-on-rails,ruby,Ruby On Rails,Ruby,我在和树宝石一起工作。我的模型层次结构是基于一个“组织”(organization)和一个整数父\ u id 我已将所有组织设置为父\u id(指向现有id),但根节点除外,它的父\u id为空 当我调用Org.hash_tree时,我得到: Org Load (1.1ms) SELECT `orgs`.* FROM `orgs` INNER JOIN ( SELECT descendant_id, MAX(generations) as depth FROM `org_hierarchies

我在和树宝石一起工作。我的模型层次结构是基于一个“组织”(organization)和一个整数父\ u id

我已将所有组织设置为父\u id(指向现有id),但根节点除外,它的父\u id为空

当我调用Org.hash_tree时,我得到:

Org Load (1.1ms)  SELECT `orgs`.* FROM `orgs` INNER JOIN (
SELECT descendant_id, MAX(generations) as depth
FROM `org_hierarchies`
GROUP BY descendant_id

) AS generation_depth
ON `orgs`.id = generation_depth.descendant_id  ORDER BY generation_depth.depth

NoMethodError: undefined method `[]=' for nil:NilClass

from /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/closure_tree-5.1.1/lib/closure_tree/hash_tree.rb:52:in `block in build_hash_tree'
关于这个问题的原因有什么想法,或者在哪里查找的技巧


一个简单的递归函数调用每个组织上的子方法,从根开始按预期工作,返回组织树。

org.rebuild!帮我解决了这个问题。层次结构表不知何故已损坏