Skip to content

Instantly share code, notes, and snippets.

@phoet
Created December 17, 2010 15:35

Revisions

  1. phoet revised this gist Jan 12, 2011. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions rails_admin_without_devise.rb
    Original file line number Diff line number Diff line change
    @@ -27,6 +27,24 @@ def can_admin?
    raise CanCan::AccessDenied if current_user.nil? || !current_user.admin?
    end
    end

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

    private

    def can_admin?
    raise CanCan::AccessDenied if current_user.nil? || !current_user.admin?
    end
    end

    # latest commits introduced new dependencies to devise...
    DEFAULT_CURRENT_USER = Proc.new do
    #return nil unless resource = Devise::mappings.keys.first {|r| signed_in?(r)}
    send("current_user")
    end

    end

    # RailsAdmin needs two additional things to get it working with my OmniAuth setup
  2. phoet revised this gist Dec 17, 2010. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions rails_admin_without_devise.rb
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,8 @@
    # looks like it's broken, but it just does not install devise
    # you may also remove the app/config/locales/devise.en.yml
    rails generate rails_admin:install_admin
    # create the history entity
    rake db:migrate

    # create an initializer for using CanCan with RailsAdmin
    # found here: http://everydayrails.com/2010/12/17/rails-admin-panel.html
  3. phoet created this gist Dec 17, 2010.
    45 changes: 45 additions & 0 deletions rails_admin_without_devise.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # add RailsAdmin to the Gemfile
    # do NOT add devise
    gem "rails_admin", :git => "git://github.com/sferik/rails_admin.git"

    # run Bundler
    bundle

    # run the generator for RailsAdmin
    # looks like it's broken, but it just does not install devise
    # you may also remove the app/config/locales/devise.en.yml
    rails generate rails_admin:install_admin

    # create an initializer for using CanCan with RailsAdmin
    # found here: http://everydayrails.com/2010/12/17/rails-admin-panel.html
    # config/initializers/rails_admin.rb
    require "rails_admin/application_controller"

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

    private

    def can_admin?
    raise CanCan::AccessDenied if current_user.nil? || !current_user.admin?
    end
    end
    end

    # RailsAdmin needs two additional things to get it working with my OmniAuth setup
    # 1. an email attribute on the User class, which i simply redirected to the nickname
    # app/models/user.rb
    def email
    nickname
    end

    # 2. a logout route that matches Devises name schema
    # config/routes.rb
    match '/auth/destroy_user_session', :to => 'sessions#destroy_user_session', :as => :destroy_user_session

    # this simply redirects to the original logout
    # app/controllers/sessions_controller.rb
    def destroy_user_session
    redirect_to destroy_session_path
    end