开发者

Operators in ruby on rails not recognized

I wrote this function:

  if params[:id] > @max
   @page = @max
    end
开发者_如何学Go

Here @max is an integer, and the value of params[:id] isn't nil.

It says there is a problem in the first line, and problem is:

undefined method `>' for nil:NilClass

It doesn't recognize > as an operator. Why is it so?


Yes, params[:id] is nil. That's what that error means. Perhaps you wanted params['id'] instead? If you have access to the console for your running app, try p params, params[:id] and make your request again to see what values there are, and the value of params[:id].


It doesn't recognize it as an operator on the NilClass like it says. params[:id] must be nil. Check your Rails logs for the list of parameters coming into the request. My guess is that the param is named differently than you think. Try if params[:id].present? && params[:id] > @max or params[:id].to_i > @max to work around the exception.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜