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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 23, 2006, at 5:26 PM, Kurth Bemis wrote:> 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?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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I do see. Exactly what I was looking for. Thank You. On 11/23/06, Xavier Noria <fxn-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> > On Nov 23, 2006, at 5:26 PM, Kurth Bemis wrote: > > > 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? > > 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 > > > > > >-- Ozone Computer Computer consulting, Services and Sales. 9 Main Street Springfield, Vermont 1-802-885-8030 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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? -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On 11/23/06, Phlip <phlip2005-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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? > > -- > Phlip > http://www.greencheese.us/ZeekLand <-- NOT a blog!!! > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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.> > -- > > Phlip > > http://www.greencheese.us/ZeekLand<-- NOT a blog!!!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---