Last active
August 29, 2015 14:16
-
-
Save rissajeanne/23f6f2335336cfc37818 to your computer and use it in GitHub Desktop.
Rails whitelist of IPs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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