In Rails how to change attribute of a model after it is initialized and display in the form?

You have an application in Rails 4, there is a field in database with type BINARY 16 (it uses gem activeuuid).
You must bring the form to edit, in this case, before the withdrawal and preservation of the shape to convert to a readable form and back.
For example, there is a model HostInterface, where the mac address just in binary, added to the model method for field name
def mac_address
 self[:mac_address].unpack('C*').join(':') if self[:mac_address]

The problem is that the conversion only works in the console, the rail and the derivation of the form appears 'unicode-hell' (binary the same).
A form is displayed as standard using form_for and fields_for (tried simple_form, but it generally falls with Encoding-error).
Where to dig to solve this issue?
Thank you.
September 19th 19 at 00:14
1 answer
September 19th 19 at 00:16
In the model

def my_mac_address
 mac_address && mac_address.unpack('C*').join(':')

def my_mac_address= (value)
 mac_address = pack(value)

In the form use my_mac_address instead of mac_address
Thanks for the reply. Did the conversion at the request of carer after_initialize, with Sobranie using before_save - Beverly_Kris commented on September 19th 19 at 00:19

Find more questions by tags ProgrammingRubyRuby on RailsWeb Development