Having a true or false output is fine when it comes to code no human is ever going to read but, when it comes to the human eye; We want to communicate our answer in the best way UX can handle. There is a simple way to handle this so you can make your method global.
module ApplicationHelper
def humanize_boolean(value)
case value
when true
"Yes"
when false
"No"
when nil
"Undefined"
else
"Invalid"
end
end
end
Add this handy method to your application_helper.rb and use anywhere on your "views" files.
<%= humanize_boolean(post.published) %>
Top comments (1)
This was helpful, thank you!