Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4250496
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:32:10+00:00 2026-05-21T04:32:10+00:00

This is a two part question. I’m needing to restrict a rails site that

  • 0

This is a two part question. I’m needing to restrict a rails site that I’m throwing on development server to only a few IP addresses, so the public can’t access it. (Basic HTTP auth doesn’t ‘entirely’ work as the auth breaks a Flash uploader in the project.)

Based on what I’ve Googled, this is what I’ve come up with in my routes file…

class WhitelistConstraint
  def initialize
    @ips = '127.0.0.1'
  end

  def matches?(request)
    @ips.include?(request.remote_ip)
  end
end

MyProject::Application.routes.draw do
  constraints WhitelistConstraint.new do
     # all my routing stuff here
  end
end

Works pretty good. However, I need to modify this in order to work with several IP addresses. I tried using a array on @ips, as well as looping through an each loop, but neither worked.

On top of that, the second part of my question…I may need to check only against a segment of the IP, like ‘127.0.0’. How would I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:32:11+00:00Added an answer on May 21, 2026 at 4:32 am

    I didn’t know you could do this through routes, my approach would be to just have a before_filter in the ApplicationController and just have something that does:

    before_filter :protect
    
    def protect
      @ips = ['127.0.0.1', '203.123.10.1'] #And so on ...]
      if not @ips.include? request.remote_ip
         # Check for your subnet stuff here, for example
         # if not request.remote_ip.include?('127.0.0.1')
         render :text => "You are unauthorized"
         return
      end
    end
       
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a two part question. A dumb technical query and a broader query
This is a two part question. Is it possible to take advantage of xVal
This is a two-part question: First, I am interested to know what the best
This is a two part question; firstly, does anyone out there have some insight
This is a two-part question: 1. The original .NET print classes (in System.Drawing.Printing) are
This is a two part question. The first is a specific question about DataSets
This is a two part question from a WPF animation newbie. First, here is
This is a two part question. Q1: Can cURL based request 100% imitate a
This is a two-part question. I'm using jQuery for a project and wanting to
This is a two part question: Part 1 First, dealing with calculating the entropy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.