Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

params[...] comparison raises "undefined method `>' for nil:NilClass" error in ruby on rails

I want to check below:

if params[:hidval] > "0"
OR
if !params[:hidval] < "1"

But it gave me error below:

undefined method `>' for nil:NilClass

How do I check above conditions in ruby on rails?

like image 487
user88 Avatar asked Aug 25 '26 04:08

user88


1 Answers

The error message says it all. Make sure, the param actually exists. You try to compare nothing (NilClass) with a number. (which is actually a string, that will be your next problem)

Probably correct would be:

if params[:hidval].present? && params[:hidval] > 0
 # Do something ...
end
like image 160
Sebastian Wramba Avatar answered Aug 27 '26 16:08

Sebastian Wramba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!