Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.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 用户模型的rails未定义方法_Ruby On Rails_Undefined - Fatal编程技术网

Ruby on rails 用户模型的rails未定义方法

Ruby on rails 用户模型的rails未定义方法,ruby-on-rails,undefined,Ruby On Rails,Undefined,rspec测试未通过此项: Failure/Error: before { visit user_path(user) } ActionView::Template::Error: undefined method `picking?' for nil:NilClass 触发此错误的代码是: <% if current_user.picking?(post) %> 为什么测试失败?为什么当前用户是nil类?您确定来自\u memory\u token的用户\u返回了什么吗?我建

rspec测试未通过此项:

Failure/Error: before { visit user_path(user) }
ActionView::Template::Error:
undefined method `picking?' for nil:NilClass
触发此错误的代码是:

<% if current_user.picking?(post) %> 

为什么测试失败?为什么当前用户是nil类?

您确定来自\u memory\u token的
用户\u返回了什么吗?我建议使用
debugger
pry
来调试代码。我发现后者更容易使用,但它似乎缺少第一个变量的功能。

是的,当前的用户变量在系统的其他部分工作得很好system@ksol,pry可以通过插件进行增强,以提供调试器的大部分功能:banisterfiend.wordpress.com/2012/02/14/the pry生态系统/+0。句子以大写字母开头,您还没有突出显示所有代码。
def current_user=(user)
  @current_user = user
end

def current_user
  @current_user ||= user_from_remember_token
end