Skip to content

Instantly share code, notes, and snippets.

@tachiba
Forked from grosser/rails_admin_without_devise.md
Last active December 10, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tachiba/4452504 to your computer and use it in GitHub Desktop.
Save tachiba/4452504 to your computer and use it in GitHub Desktop.

Using rails_admin without devise

Having a buckload of code to authorize users on your application is something you may like or not. Speaking for myself I hate it. But I still love rails_admin, here's how you install it without devise. Thanks to phoet for providing the hints in the gist I have forked from.

Add RailsAdmin to your Gemfile

do NOT add devise

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

Run Bundler

bundle install

Run the generator for RailsAdmin

rails g rails_admin:install

Remove everything you do not need e.g. migrations or config/locales/devise* Cleanup the Gemfile and routes.rb etc

Migrate the history entity

rake db:migrate

Create an initializer for your own admin authorization code

In config/initializers/rails_admin.rb:.

class RailsAdminUser
  def self.username
    'admin'
  end

  def self.email
    'admin@admin.com'
  end
end

RailsAdmin.config do |config|
  config.current_user_method { RailsAdminUser }
  config.main_app_name { ['Recommended Games', 'Admin'] }
  config.authenticate_with{}
  config.authorize_with do
      authenticate_or_request_with_http_digest('Site Message') do |username|
        username == 'hoge' ? 'moge' : false
      end
  end
end
@tachiba
Copy link
Author

tachiba commented Jan 4, 2013

it works fine!

rails (3.2.5)
rails_admin (0.3.0)

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