如何检查参数是真还是假? [英] How to check if a param is true or false?

查看:48
本文介绍了如何检查参数是真还是假?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这真的让我绞尽脑汁,但也许我正在努力.

This is really racking my brain, but maybe I'm trying to hard.

我通过 URL 传递参数 (example.com?debug=true)

I'm passing a param via a URL (example.com?debug=true)

所以我基本上想说:

if params[:debug] == true
 do xyz
else
 do abc
end

但是无论出于何种原因,if 语句都没有像它应该做的那样工作.

But for whatever reason that if statement just isn't doing like it seems like it should.

是否有更好的方法来执行基于参数为真或假的 if/else 语句?

Is there a better way to do that if/else statement based on a param being true or false?

调试参数的值为 true、无值或 false(就 URL 而言).

The debug param will either have a value of true, no value, or a value of false (as far as the URL goes).

推荐答案

参数以字符串形式出现,因此您需要与 "true" 进行比较,而不是 true.

params come in as strings, so you need to compare against "true", not true.

这篇关于如何检查参数是真还是假?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆