I have a problem in my Rails project. In previous projects (not Rails) I just used the "inet" type in PostgreSQL to store an IP address with a subnet, something like this:
192.168.1.0/30
192.168.1.1/30
192.168.1.2/30
192.168.1.3/30
This was a good method to store the IP and the subnet in one field. Now I am using the inet type in Rails (4.0.1) and Ruby (2.0.0 p247), but as I read and tried, Rails converts it to the IPAddr object. But this IPAddr Object is destroying my format. It converts the four examples above to the following:
192.168.1.0/30
Is there a way to prevent Rails doing that or is there a way to substitute it with a string? Or maybe another gem?
The problem occurs when I try to store something, and even when I try to read an existing value from the database.
Just to be more granular:
IPAddr.new("192.168.1.2/255.255.255.252")
Creates the database entry:
192.168.1.0/24