Skip to content

How to output a boolean true or false to display yes or no in Ruby on Rails

Posted on 12 April 2006

So you have a boolean check in your database and you want to convert the output from saying "true" or "false" to something more readable like "yes" or "no". It's as easy as:


<%= article.show? ? 'yes' : 'no' %>

Where article is the object and show is the field in my database with the boolean 1 or 0 stored.

View the snippets archive ››

3 comments made

Pepe commented on 26 Sep 07 at 08:08

Please, con you check the article? the code is not avaiable.

Paul commented on 26 Sep 07 at 08:31

Hi Pepe,

The code is there, it reads:

article.show? ? 'yes' : 'no'

Can you see the code in the html source? Perhaps there is a css bug here? What browser are you using?

Thanks, Paul.

Chris B commented on 30 Jan 08 at 14:04

Thanks so much! I was going crazy trying to figure this out. Sometimes the API and I are speaking different languages…

It worked perfectly in my application.

Got something to say?

About

Paul is a web developer for Kyanmedia web agency. He's lucky enough to write in Ruby on Rails full-time and uses this site to post snippets of code.

Contact

my name at gmail.com

More snippets

Take a look in the archive

Need a website?

Contact my employer. Make sure to check out our portfolio of work.

Hosting

I recommend hostingrails.com