Hi people,
I’m developing my first rails app, and I’m having a little issue with
model validations:
==
require_gem ‘netaddr’
(…) (AR model definition)
protected
def validate
@eui = NetAddr::EUI.create(mac).address(:Delimiter=>’:’)
#@eui.address(:Delimiter=> ‘.’)
rescue NetAddr::ValidationError
errors.add(mac, “Incorrect MAC address format”)
end
My idea is to ensure at the model level, that a MAC address is
properly filtered and saved using the following format:
0000.1111.2222
… and automatically convert the following netaddr-supported formats
to the above one:
00:00:11:11:22:22
00-00-11-11-22-22
(…)
Now when I try to add a MAC using any format, it saves ‘000011112222’
on the DB and I cannot figure why it’s happening by looking at netaddr
code.
NetAddr uses gsub!(/[.:-]/, ‘’) all around to remove formating
chars, but ".address(:Delimiter =>’.’) " should put ‘.’-format back to
the MAC string, shouldn’t it ?
Thanks in advance.