[英]Undefined method '*' for nil:Nilclass
I am working on an application that is like a forum. 我正在开发一个类似论坛的应用程序。 It displays all data in a table. 它显示表中的所有数据。 So what I am trying to do is sort the dates in the table in ascending order. 所以我要做的是按升序对表中的日期进行排序。
Here's what I am trying to do: 这是我想要做的:
def pullTenRecords
if session[:page] == 0
tenRecords = Consciousmess.limit(10).offset(0)
orderedTenRecords = tenRecords.order(created_at: :asc)
else
tenRecord = Consciousmess.limit(10).offset(session[:page] * 10)
orderTenRecords = tenRecord.order(created_at: :asc)
end
end
My problem is it says undefined undefined method '*' for Nil:NilClass. 我的问题是它为Nil表示未定义的未定义方法'*':NilClass。 I do realize there are some posts about this on StackOverflow but none of the posts have really helped in terms of solving my issue. 我确实在StackOverflow上有一些关于这个的帖子,但是在解决我的问题方面没有一篇文章真的有帮助。 Thanks. 谢谢。
Your session[:page]
is nil
. 你的session[:page]
是nil
。 Just set default value if it nil
: 如果nil
只需设置默认值:
def pullTenRecords
session[:page] ||= 0
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.