Forum: Ruby on Rails modeling ipaddresses

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
28bb07a60e74c2467cc944364fe4075a?d=identicon&s=25 jm (Guest)
on 2005-11-21 06:30
Bare with me as I outline the set up. I have a db table with the schema

 id       int(10) unsigned
 ipaddr   int(32) unsigned
 maskbits int(8)  unsigned

and a web form where the use enters the ip address and mask. The
controller and view are easy enough. The model on the other hand is
causing problems. As the ip address is entered in the form as
"ddd.ddd.ddd.ddd" with a netmask between 0 and 32. This is stored as an
integer so as to be able to use sql to do netmask operations, I need to
typecast between the two in the model. I found the composed_of
directive, but am scratching my head when it comes to applying this to
the IPAddr class. It is beginning to look as if I'll have to
re-implement the IPAddr class as a value object unless someone cares to
give me a few pointers. Is there an esay way to do what I wish to do?

This topic is locked and can not be replied to.