Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. huned revised this gist Aug 31, 2011. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions rails_admin_without_devise.md
    Original file line number Diff line number Diff line change
    @@ -36,11 +36,11 @@ In `config/initializers/rails_admin.rb`:.

    private

    def is_admin?
    if current_user.nil? || !current_user.admin?
    head(:forbidden)
    false
    def is_admin?
    if current_user.try :admin?
    head :forbidden
    false
    end
    end
    end
    end
    end
  2. @Overbryd Overbryd revised this gist Jul 6, 2011. 2 changed files with 46 additions and 65 deletions.
    46 changes: 46 additions & 0 deletions rails_admin_without_devise.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    # 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](http://github.com/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"

    ## 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?

    private

    def is_admin?
    if current_user.nil? || !current_user.admin?
    head(:forbidden)
    false
    end
    end
    end
    end
    65 changes: 0 additions & 65 deletions rails_admin_without_devise.rb
    Original file line number Diff line number Diff line change
    @@ -1,65 +0,0 @@
    # 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 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
    # 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

    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
    # 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
  3. @phoet 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
  4. @phoet 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
  5. @phoet 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