rails mysql BLOB type - to_xml returns binary, would like to force to string
I am running RoR, Ruby 1.8.6/Rails 2.3.2.
I am persisting a String within a model object to MySQL to a Blob field. For a number of reasons, I have to use MySQL Blob data type instead of a Text data type, yet I want Rails to treat the field as a regular String (instead of a binary Str开发者_开发技巧ing - which is what I think it is doing?).
How can I force this? Everything works well in the display of the pages, the main issue is XML that is being produced.
A specific example is a "description" field of type Blob in MySQL displays perfectly in the HTML ERB, but when using the to_xml method on that model object the resulting XML is:
<description type="binary" encoding="base64">
VGhpcyB0d28tc2NyZWVuIGZvcm0gYWxsb3dzIGJ1c2luZXNzIGN1c3RvbWVy
cyB0byByYXRlIHRoZWlyIGxldmVsIG9mIHNhdGlzZmFjdGlvbiBhbmQgcmVx
dWVzdCB0byBzcGVhayB3aXRoIG1hbmFnZW1lbnQuIEl0IGlzIGVzcGVjaWFs
bHkgZGVzaWduZWQgZm9yIHRoZSBDb21taXNzaW9uIG9uIFZvY2F0aW9uYWwg
UmVoYWJpbGl0YXRpb24u
</description>
I just want it to appear be formatted as a normal string field like:
<description>test description</description>
What are the best ways to force this? I've been searching and reading through docs, but haven't been finding any helpful suggestions.
I appreciate any and all help, thank you
I ended up monkey patching the XmlSerializer to treat binary data as text. I will never have to send binary data down in pure binary form via XML, so this was a valid option - not perfect, but in doing research couldn't find any way to override the default column settings.
精彩评论