Here is the code I wrote in the application controller:
class ApplicationController < ActionController::Base protect_from_forgery before_filter :redirect_if_bolivia private def redirect_if_bolivia if (bolivia_ip_block).includes? request.remote_ip
So basically, what is the easiest way to check if request.remote_ip belongs to the IP block in Bolivia?
I donβt think that iterating through each block and spitting out the corresponding IP address, adding it to the array is effective. In fact, this would lead to the creation of an array of thousands of records for each individual query.
I am sure this is not a new problem, so I would like to find a proven solution.
Maybe I can check if the first three octets match, then it belongs to the block? How do I make this simple string comparison in Ruby?
source share