Skip to content

Instantly share code, notes, and snippets.

@grosser
Forked from huned/rails_admin_without_devise.md
Last active July 27, 2016 06:25
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save grosser/1278355 to your computer and use it in GitHub Desktop.
Save grosser/1278355 to your computer and use it in GitHub Desktop.
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

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

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