Ruby - rails - Working with logical false - doesn't display anything

I have an entry in my db which is a boolean field (true / false).

Field archived. When archived correctly, all of this works fine to output true:

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

BUT, when the archived value is false, it does not output anything to any of the above. How can I get false output when the field is FALSE?

thank

0
source share
3 answers

Try it .to_sin the box?

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

I prefer to use .inspectlogging output. I find its output more useful if you get a null value.

ruby-1.8.7-p302 > nil.to_s
 => "" 
ruby-1.8.7-p302 > nil.inspect
 => "nil" 
ruby-1.8.7-p302 > false.to_s
 => "false" 
ruby-1.8.7-p302 > false.inspect
 => "false" 
ruby-1.8.7-p302 > 
+3
source

false.to_s == 'false', Rails.logger.info :

> puts true
true
> puts false
false
> Rails.logger.info true
true
> Rails.logger.info false
+1

Source: https://habr.com/ru/post/1786217/


All Articles