I have a field of type bit in a MySQL database, but I'm not sure how to access the value.
The ruby debug method gives me (note the spaces, they are probably invisible characters stored in binary form):
--- &id001 !ruby/object:Room
attributes:
bit_field_false: !binary |
AA==
bit_field_true: !binary |
AQ==
bit_field_false and bit_field_true should be false and true respectively. I've also noticed some weird properties:
- When I convert them to integers, they both show as
0 - When I extract truth values, ie,
<%= @room.bit_field_true ? "true" : "false" %>and<%= @room.bit_field_false ? "true" : "false" %>, they both yieldtrue - When I show them as strings they show as empty strings
How to I get their respective values? Do the binary values mean anything?
The end goal is to show them in a checkbox, and I have something like:
<% form_for(@room) do |room_f| %>
<%= check_box_tag :room_bit_field_false %><br/>
<%= check_box_tag :room_bit_field_true %><br/>
<% end %>
but it always shows as unchecked. I'm not certain this is how to create checkboxes for this set up, so this could be wrong as well, but regardless I want to know how to extract the bit values in code.
For reference, I'm using Ruby on Rails 2.3.2, with the mysql adapter and mysql Ver 14.14 Distrib 5.5.10, for osx10.6 (i386).