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

  • SEARCH
  • Home
  • 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 6254567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:12:06+00:00 2026-05-24T14:12:06+00:00

I want to validate an IP address before I login in my Admin Controller.

  • 0

I want to validate an IP address before I login in my Admin Controller.

before_filter :validate_ip

How should I create this IP validation? I just want to write the IP addresses that have access in the controller.

  • 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-24T14:12:07+00:00Added an answer on May 24, 2026 at 2:12 pm

    The first solution is dynamic, because you can populate the array in runtime:

     def validate_ip
       valid = %w[127.0.0.1 10.0.0.1]
       redirect_to(login_path) unless valid.include?(request.remote_ip)
     end
    

    The other way to restrict IPs is, to use constraints in your routes.rb:

    get '/admin' => 'admin#super_secure_action', :constraints => { :ip => %w[127.0.0.1 10.0.0.1] }
    
    # or
    
    constraints(:ip => %w[127.0.0.1 10.0.0.1]) do
      # Every route defined in here will be restricted.
      get '/admin' => 'admin#super_secure_action'
    end
    

    For more information about Rails and Routes, be sure to check out: Rails Dispatch – The Powerful New Rails Router.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to validate my input, should I make validation code as private
I want to validate a registration form that accepts an email address in the
I want to validate a set of credentials against the domain controller. e.g.: Username:
I want to validate a condition before doing the next step, but only raise
in my application i want to validate the telephone numbers, how can i write
I want to validate the given address (address, city, state, zip) to the USPS
I want to validate that a hostname/IP address is on the public internet; that
I want a regular expression for javascript to validate host address like http://192.168.10.10:8089/ and
I want to validate my form with Ajax Validation method.So for I have made
I have a form that validates the email address and I want to be

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.