I have an ActiveRecord model with a boolean attribute. If I call
to_json on an instance of this model, a get something like the
following:
"{attributes : { my_boolean : \"0\" } }"
or
"{attributes : { my_boolean : \"1\" } }"
why is my boolean attribute being converted to a string?
if i call my_model_obj.attributes.to_json i get: "{ my_boolean :
false }" or "{ my_boolean : true }", which are both valid JSON
representation according to the grammar specified at http://www.json.org,
and definitely the preferred representation when testing for truth in
javascript
json_str = "{attributes : { my_boolean : \"0\" } }"
obj = eval(json_str)
if(obj.attributes.my_boolean) {
// shouldn''t execute this bc my_boolean is false
}
can anyone tell me why this is? or what i might be doing wrong?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---