Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Using RailsAdmin without devise

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://"

Run Bundler

bundle install

Run the generator for RailsAdmin

It works and just does not install devise. You may also want to $ rm config/locales/devise*.

rake rails_admin:install

Migrate the history entity

rake db:migrate

Create an initializer for your own admin authorization code

In config/initializers/rails_admin.rb:.

require "rails_admin/application_controller"

module RailsAdmin
  class ApplicationController < ::ApplicationController
    before_filter :is_admin?


    def is_admin?
      if current_user.nil? || !current_user.admin?
Copy link

adedip commented Feb 4, 2013

This ain't working for me, as I run the installer it prompts for devise and it force devise installation.

To make it work, I had to run the installer, that fails, while failing I've removed everything dealing with devise, that repeat the installer and migrate, that way worked.

I think would be better to have a proper fork without devise at all. Thanks ;)

Copy link

eugenemiretsky commented Mar 6, 2013

I'm getting the following error:
ActionView::Template::Error (Could not find a valid mapping for # From here
6: - if _current_user
7: - if user_link = edit_user_link
8: %li= user_link
9: - if logout_path.present?
10: %li= link_to content_tag('span', t('admin.misc.log_out'), :class => 'label label-important'), logout_path, :method => Devise.sign_out_via
11: - if _current_user.respond_to?(:email) &&
12: %li= image_tag "#{(request.ssl? ? 'https://secure' : 'http://www')}{Digest::MD5.hexdigest}?s=30", :style => 'padding-top:5px'
devise (2.2.3) lib/devise/mapping.rb:42:in find_scope!'

Any help would be appreciated!

Copy link

shacker commented May 29, 2013

Ditto - I get "NameError: uninitialized constant Devise" with or without this fix.

Copy link

nicholas-johnson commented Jun 21, 2013

Awesome. Since I already had a method require_admin in my application controller, I only needed:

require "rails_admin/application_controller"

module RailsAdmin
  class ApplicationController < ::ApplicationController
    before_filter :require_admin

Copy link

jassa commented Jul 5, 2013

@eugenemiretsky and @shacker: set config.current_user_method { false } in your initializer

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