boolean to text?

I'm new to RoR, but learning quickly (I hope)

I have stored a boolean value in my database (is_organic). How do I
convert the value to something meaningful. In this case 1 = Organic.

I suppose I could do it with a loop, but that seems wasteful. Are
these functions available in RoR?

~k

You don't. In the Ruby side you use always Ruby booleans:

   thing.is_organic = true
   thing.toggle! :is_organic
   thing.is_organic? # provided by AR if type is boolean

   nonorganics = Thing.find_all_by_is_organic(false)

You see.

-- fxn

I do see.

Exactly what I was looking for.

Thank You.

Xavier Noria wrote:

  thing.is_organic = true
  thing.toggle! :is_organic
  thing.is_organic? # provided by AR if type is boolean

  nonorganics = Thing.find_all_by_is_organic(false)

Suppose I miss the C++ metamacro trick. Suppose I have global constants:

  YoDude = 2
  WhatsUp = 3

Now I want a 2 to produce 'YoDude' as a string, and 3 to produce 'WhatsUp'. Preferrably without overloading 2 and 3, and without creating a new lookup table. (That would happen if we go over 10 or so constants and I return control to the OnsiteCustomer.)

How do I do an enumeration that can reflect its values as strings?

Hi, I would recommend using a Hash to achieve your goal. Also, I
would highly recommend getting a good understanding of the Ruby
language an its associated idoms.
You'll find this to be very helpful when you're working with the Rails
web development framework.

Good luck,

-Conrad

Conrad Taylor wrote:

Hi, I would recommend using a Hash to achieve your goal.

Ooh, I guess that where I said "without creating a new lookup table", I
could have extended that to "and not a Hash". Same idiom different
framework.