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 778193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:43:34+00:00 2026-05-14T19:43:34+00:00

I want the /admin route on my rails app to be protected by using

  • 0

I want the /admin route on my rails app to be protected by using .htaccess password files – is this possible?

  • 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-14T19:43:34+00:00Added an answer on May 14, 2026 at 7:43 pm

    Rails has a built-in helper for this, you could place this in your application controller:

    protected
      def authenticate
        authenticate_or_request_with_http_basic do |username, password|
          username == "admin" && password == "test"
        end
      end
    

    Then use a before_filter on any controllers you want to protect (or just stick it in the application controller to block the whole site):

    before_filter :authenticate
    

    This method works on Nginx as well as Apache, which is an added bonus. It doesn’t, however, work if you have full page caching enabled – as the visitor never hits the Rails stack; it won’t kick in.

    Edit
    Just noticed that you specified the /admin route. All my admin controllers inherit from an AdminController. You could set yours up like so:

    /app/controllers/admin/admin_controller.rb

    class Admin::AdminController < ApplicationController
      before_filter :authenticate
      protected
        def authenticate
          authenticate_or_request_with_http_basic do |username, password|
          username == "admin" && password == "test"
        end
      end
    end
    

    Then have all your controllers extend the admin controller, eg:

    class Admin::ThingsController < Admin::AdminController
    

    My routes are setup like so:

    map.namespace :admin do |admin|
        admin.resources :things
    end
    

    Hope that helps.

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

Sidebar

Related Questions

I want to have a web based admin to upload, delete files and folders
I have a Rails app with a Route resource, and a Route controller (not
Is is possible to create a recursive route in Rails? I have an application,
I have this route: # config/routes.rb map.namespace :backshop, :path_prefix => '/:shop_id/admin' do |backshop| backshop.resources
From the admin panel I want to populate a slug field based on a
...I want to Show the 'delete' button when user is an admin, and show
I have an ASP.NET 3.5 e-commerce site that has an admin section. I want
I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal
I thought this would be fairly easy, but I'm totally baffled. I want one
So I am creating a website that I want to have an admin directory

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.