So I've converted the IPs to integers using IPAddr, which makes it a
whole lot easier to see if an incoming IP fits a certain range.
The code I'm looking at now is:
@request_ip = IPAddr.new(request.remote_ip)
ips = IpRanges.find(:all)
ips.each do |ip|
range = ip.start_ip_integer..ip.end_ip_integer
if range.include?(@request_ip.to_i)
@ip_range = ip
end
end
render :text => @ip_range.group
Looks painfully slow to iterate thru every row like that - and I keep it
all in my controller when I assume it should be refactored into my
IpRange-model?
Any way to speed things up?