Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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 为什么我不能读取错误页面REPL上的参数?_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 为什么我不能读取错误页面REPL上的参数?

Ruby on rails 为什么我不能读取错误页面REPL上的参数?,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我正在尝试调试一个特定问题,并且安装了gembetter\u errors。我得到了一个漂亮的错误页面,其中嵌入了REPL,允许我检查当前请求的各个元素的值 这是生成错误的URL: http://localhost:3000/nodes/new?parent_id=16 问题是,当我尝试检查参数的值时,我得到以下错误: >> params[:parent_id] !! #<NameError: undefined local variable or method `params

我正在尝试调试一个特定问题,并且安装了gem
better\u errors
。我得到了一个漂亮的错误页面,其中嵌入了REPL,允许我检查当前请求的各个元素的值

这是生成错误的URL:

http://localhost:3000/nodes/new?parent_id=16

问题是,当我尝试检查参数的值时,我得到以下错误:

>> params[:parent_id]
!! #<NameError: undefined local variable or method `params' for #<Node:0x007fc4db2cd678>>
>> node_params
!! #<NameError: undefined local variable or method `node_params' for #<Node:0x007fc4db2cd678>>
>> node_params[:parent_id]
!! #<NameError: undefined local variable or method `node_params' for #<Node:0x007fc4db2cd678>>
>> params
!! #<NameError: undefined local variable or method `params' for #<Node:0x007fc4db2cd678>>
>>
REPL确实有效,如下所示:

>> Node
=> Node(id: integer, family_tree_id: integer, created_at: datetime, updated_at: datetime, name: string, ancestry: string, ancestry_depth: integer, max_tree_depth: integer)
>> Node.first
=> #<Node id: 7, family_tree_id: 2, created_at: "2015-01-17 18:22:13", updated_at: "2015-01-17 18:24:50", name: "Self", ancestry: nil, ancestry_depth: 0, max_tree_depth: 0>
>>
>节点
=>节点(id:integer,family\u tree\u id:integer,创建时间:datetime,更新时间:datetime,名称:string,祖先:string,祖先深度:integer,最大树深度:integer)
>>Node.first
=> #
>>
不确定这是否重要,但这是原始请求上的错误消息:

NoMethodError at /nodes/new
undefined method `parent_id' for #<Node:0x007fc4db2cd678>
/nodes/new处的命名错误 未定义的方法“parent_id”#
这意味着您位于作为
自身
作为
节点
对象的方法内部,而不是控制器方法内部。查看左侧的堆栈跟踪,查看您当前在哪个方法(以及哪个对象)下执行代码。

Node\method\u missing
。但是我不明白,
params
难道不是一个简单的ActionController方法吗?是的,但是你不在ActionController对象的内部,你在一个节点对象的内部。当您在repl in better_errors中键入某些内容时,您将该方法发送到当前对象。在本例中,它是一个节点对象。它就像一个调试器,你可以在调试器中跳进跳出帧,你可以看到变化。你是对的。我刚刚做了
self
,它返回了
节点
对象。因此,如果参数在
请求参数
下的信息中,我如何后退一步并实际获取参数?在左侧栏中,有一个帧列表。您当前处于
节点#方法_缺失
,滚动直到看到控制器中的帧,然后单击它,您将处于正确的上下文中
NoMethodError at /nodes/new
undefined method `parent_id' for #<Node:0x007fc4db2cd678>