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

Revisions

  1. grosser revised this gist Apr 1, 2013. 1 changed file with 6 additions and 8 deletions.
    14 changes: 6 additions & 8 deletions rails_admin_without_devise.md
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,20 @@
    # 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"
    gem "fastercsv", :platform => :ruby_18

    ## Run Bundler
    ## Bundle

    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
    Remove everything you do not need: migrations + added devise in Gemfile

    ## Create an initializer for your own admin authorization code

    @@ -35,4 +30,7 @@ RailsAdmin.config do |config|

    config.main_app_name { ['My App', 'Admin'] }
    end
    ```
    ```

    # Thanks
    Thanks to [phoet](http://github.com/phoet) for providing the hints in the gist I have forked from.
  2. grosser revised this gist Apr 1, 2013. 1 changed file with 10 additions and 23 deletions.
    33 changes: 10 additions & 23 deletions rails_admin_without_devise.md
    Original file line number Diff line number Diff line change
    @@ -21,31 +21,18 @@ _do NOT add devise_
    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 FakeUser
    def self.username
    'admin'
    end

    def self.email
    '[email protected]'
    end
    end

    RailsAdmin.config do |config|
    config.current_user_method do
    authenticate_or_request_with_http_basic do |username, password|
    username == "gamesadmin" && password == "admingames"
    end
    FakeUser
    end
    config.main_app_name { ['Recommended Games', 'Admin'] }
    config.authenticate_with{}
    ```Ruby
    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
    ```
  3. grosser revised this gist Oct 11, 2011. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion rails_admin_without_devise.md
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,12 @@ In `config/initializers/rails_admin.rb`:.
    end

    RailsAdmin.config do |config|
    config.current_user_method { FakeUser }
    config.current_user_method do
    authenticate_or_request_with_http_basic do |username, password|
    username == "gamesadmin" && password == "admingames"
    end
    FakeUser
    end
    config.main_app_name { ['Recommended Games', 'Admin'] }
    config.authenticate_with{}
    end
  4. grosser revised this gist Oct 11, 2011. 1 changed file with 15 additions and 16 deletions.
    31 changes: 15 additions & 16 deletions rails_admin_without_devise.md
    Original file line number Diff line number Diff line change
    @@ -16,11 +16,11 @@ _do NOT add devise_

    ## Run the generator for RailsAdmin

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

    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
    @@ -29,19 +29,18 @@ You may also want to `$ rm config/locales/devise*`.

    In `config/initializers/rails_admin.rb`:.

    require "rails_admin/application_controller"

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

    private
    class FakeUser
    def self.username
    'admin'
    end

    def is_admin?
    if current_user.try :admin?
    head :forbidden
    false
    end
    end
    def self.email
    '[email protected]'
    end
    end

    RailsAdmin.config do |config|
    config.current_user_method { FakeUser }
    config.main_app_name { ['Recommended Games', 'Admin'] }
    config.authenticate_with{}
    end
  5. grosser revised this gist Oct 11, 2011. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion rails_admin_without_devise.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@ Speaking for myself I hate it. But I still love `rails_admin`, here's how you in
    _do NOT add devise_

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

    ## Run Bundler

    @@ -18,7 +19,7 @@ _do NOT add devise_
    It works and just does not install devise.
    You may also want to `$ rm config/locales/devise*`.

    rake rails_admin:install
    rails g rails_admin:install

    ## Migrate the history entity

  6. @huned 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
  7. @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
  8. @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
  9. @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
  10. @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