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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With