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.

About Paul

Paul works for Kyan web design agency in Surrey, UK as a Ruby on Rails developer.

Follow Paul on Twitter

Email: paulsturgess [at] gmail.com

Read more articles in the archive →

Comments...

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

    Pepe at 26 Sep 07 at 08:08

  • 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.

    Paul at 26 Sep 07 at 08:31

  • 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.

    Chris B at 30 Jan 08 at 14:04

  • No prescription needed! <a href="http:" />reductil without prescription</a> <a href="http:" />reductil no prescription</a> <a href="http:" />reductil sale</a> <a href="http:" />meridia without prescription</a> <a href="http:" />meridia no prescription</a> <a href="http:" />meridia sale</a> <a href="http:" />clonazepam without prescription</a> <a href="http:" />clonazepam no prescription</a> <a href="http:" />clonazepam sale</a> <a href="http:" />klonopin without prescription</a> <a href="http:" />klonopin no prescription</a> <a href="http:" />klonopin sale</a> <a href="http:" />xenical without prescription</a> <a href="http:" />xenical no prescription</a> <a href="http:" />xenical sale</a> <a href="http:" />ativan without prescription</a> <a href="http:" />ativan no prescription</a> <a href="http:" />ativan sale</a> <a href="http:" />cialis without prescription</a> <a href="http:" />cialis no prescription</a> <a href="http:" />cialis sale</a>

    None at 11 Jul 09 at 23:06

Got something to say?