-
-
Save grosser/1278355 to your computer and use it in GitHub Desktop.
Using RailsAdmin without devise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Thanks for the tip, updated it :)
This did not work for me. Here is my code:
RailsAdmin.config do |config|
config.authorize_with do
authenticate_or_request_with_http_basic('Site Message') do |username, password|
username == ENV["ADMIN_KEY"] && password == ENV["ADMIN_PASSWORD"]
end
end
config.actions do
dashboard # mandatory
index # mandatory
new
export
bulk_delete
show
edit
delete
show_in_app
end
config.main_app_name { ['grade-system', 'Admin'] }
end
but how to logout with this authentication?
This works well locally but doesn't seem to work with Heroku.
It doesn't break, but the /admin page bypasses the authorization window completely when accessed after being deployed to Heroku.
I may be deploying wrong.. Any tips?
How to add a normal authentication (not basic authentication) for rails admin. I have created a dedicated model Admin, apart from user table. Any tips?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't seem to work. When the HTTP Basic authentication box appears, pressing cancel without providing any credentials grants access to rails_admin. I fixed it by doing the following:
In config/initializers/rails_admin.rb: