Skip to content

Instantly share code, notes, and snippets.

@cgallagher
Created July 2, 2012 12:08
Show Gist options
  • Save cgallagher/3032940 to your computer and use it in GitHub Desktop.
Save cgallagher/3032940 to your computer and use it in GitHub Desktop.
Rack Middleware to block IP addresses to active_admin
class RestrictAddresses
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
incoming_ip_address = request.env['REMOTE_ADDR']
allowed_range = ['127.0.0.1']
if request.fullpath.include?("/admin") and !(allowed_range).include?(incoming_ip_address)
[301, {"Location" => "http://www.betapond.com"}, self]
else
@app.call(env)
end
end
def each(&block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment