Storing & querying IP addresses efficiently in Ruby on Rails

31
0

This snippet stores user IPs efficiently using the PostgreSQL inet type, which optimizes space and lookup speed. The from_same_network scope allows querying users within the same /24 subnet, useful for analytics or security checks. The update_ip method simplifies updating the IP when users log in.

Martin Sojka, Maker of CodeSnips