If I remember right, 192.168.1.0/30
is technically correct.
Here's a couple things that might help:
- In addition to IPAddr, a very good gem for working with IPv4 and IPv6 is IPAddress. It won't help much if Active Record has passed the value to IPAddr already, and it has changed the value, so you'll need to tell Active Record to use IPAddress instead.
Storing your addresses as PostgreSQL "inet" type is fine, if you intend to use PostgreSQL to handle your subnetting needs via its built-in IP functions. It's a bad idea if you want to simply store the IP address and retrieve it, as you found out. Active Record tries to honor the field type, and map it to the closest Ruby class, which is IPAddr. Instead, I always store my IPs both as a string, for fast retrieval in the form I want, and as a suitably sized integer, so I can do all my subnetting manipulations and matches in binary.
It might help if, in your query, you tell PostgreSQL to cast your value to a string before returning it to Active Record. At that point you could use IPAddress to work with the value after parsing it. How to tell Active Record to tell PostgreSQL to do that is a different question.