Skip to content

Instantly share code, notes, and snippets.

@rissajeanne
Last active August 29, 2015 14:16
Show Gist options
  • Save rissajeanne/23f6f2335336cfc37818 to your computer and use it in GitHub Desktop.
Save rissajeanne/23f6f2335336cfc37818 to your computer and use it in GitHub Desktop.
Rails whitelist of IPs
class SomeController < ApplicationController
before_filter :protect
def protect
allowed = ['127.0.0.1', '123.456.78.9']
if not allowed.include? request.remote_ip
# Render a 403 page
render(:file => File.join(Rails.root, 'public/403'), :status => 403, :layout => false)
return
end
end
# This won't get executed for those not in the whitelist
def index
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment