Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using RailsAdmin without devise

Using rails_admin without devise

Add RailsAdmin to your Gemfile

do NOT add devise

gem "rails_admin", :git => "git://github.com/sferik/rails_admin.git"

Bundle

bundle install

Run the generator for RailsAdmin

rails g rails_admin:install

Remove everything you do not need: migrations + added devise in Gemfile

Create an initializer for your own admin authorization code

In config/initializers/rails_admin.rb:.

RailsAdmin.config do |config|
  config.authorize_with do
    authenticate_or_request_with_http_basic('Site Message') do |username, password|
      username == 'foo' && password == 'bar'
    end
  end

  config.main_app_name { ['My App', 'Admin'] }
end

Thanks

Thanks to phoet for providing the hints in the gist I have forked from.

@mgartner
Copy link

mgartner commented Apr 8, 2012

This doesn't seem to work. When the HTTP Basic authentication box appears, pressing cancel without providing any credentials grants access to rails_admin. I fixed it by doing the following:

In config/initializers/rails_admin.rb:

RailsAdmin.config do |config|
  config.authorize_with do
    authenticate_or_request_with_http_basic('Site Message') do |username, password|
      username == 'foo' && password == 'bar'
    end
  end

  # rest of configuration

end

@grosser
Copy link
Author

grosser commented Apr 1, 2013

Thanks for the tip, updated it :)

@LaurMo
Copy link

LaurMo commented Oct 29, 2014

This did not work for me. Here is my code:

RailsAdmin.config do |config|
  config.authorize_with do
    authenticate_or_request_with_http_basic('Site Message') do |username, password|
      username == ENV["ADMIN_KEY"] && password == ENV["ADMIN_PASSWORD"]
    end
  end  
  config.actions do
    dashboard                     # mandatory
    index                         # mandatory
    new
    export
    bulk_delete
    show
    edit
    delete
    show_in_app
  end
  config.main_app_name { ['grade-system', 'Admin'] }
end

@vorant94
Copy link

vorant94 commented Apr 26, 2015

but how to logout with this authentication?

@SpencerCloud
Copy link

SpencerCloud commented May 24, 2016

This works well locally but doesn't seem to work with Heroku.
It doesn't break, but the /admin page bypasses the authorization window completely when accessed after being deployed to Heroku.
I may be deploying wrong.. Any tips?

@inv-akhils
Copy link

inv-akhils commented Jul 27, 2016

How to add a normal authentication (not basic authentication) for rails admin. I have created a dedicated model Admin, apart from user table. Any tips?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment