RubyRails ActiveRecord base64 encode/decode of binary data

Hi,
I have binary images stored in a table which I wish to encode/decode
with
base64 before reading into html object:

.

How can I do this in RubyRails?


Regards

Andrew

controller:
require ‘base64’
@data = Base64.encode64(Image.find(:first).data)

view:
<object data="data:image/foo;base64,<%= @data %>>