ruby - rails - 处理布尔错误 - 它不输出任何内容 [英] ruby - rails - Dealing with a Boolean False- It outputs nothing

查看:41
本文介绍了ruby - rails - 处理布尔错误 - 它不输出任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一个布尔字段(真/假)的记录.

I have record in my db that is a boolean field (true/false).

该字段已存档.当存档为真时,所有这些都可以很好地输出真:

The field is archived. When archived is true all these work great to output true:

  Rails.logger.info @commentable.archived
  Rails.logger.info @commentable.archived?
  Rails.logger.info !!@commentable.archived?

但是当存档为假时,它不会为上述任何一个输出任何内容.当字段为 FALSE 时,如何获得 false 输出?

BUT when the archived is false, it outputs nothing for either of the above. How can I get an output of false when the field is FALSE?

谢谢

推荐答案

在现场试试 .to_s?

irb(main):001:0> false.to_s
=> "false"
irb(main):002:0> true.to_s
=> "true"
irb(main):003:0>

这篇关于ruby - rails - 处理布尔错误 - 它不输出任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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