Created
December 17, 2010 15:35
-
-
Save phoet/745123 to your computer and use it in GitHub Desktop.
Using RailsAdmin without devise
This file contains 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 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 |
me too ,I don't want to use devise ,and do as rails_admin wiki help .define my own authticate function .but still have this error . why?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting the following error:
ActionView::Template::Error (Could not find a valid mapping for #<User id
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) && _current_user.email.present?
12: %li= image_tag "#{(request.ssl? ? 'https://secure' : 'http://www')}.gravatar.com/avatar/#{Digest::MD5.hexdigest _current_user.email}?s=30", :style => 'padding-top:5px'
devise (2.2.3) lib/devise/mapping.rb:42:in
find_scope!' /home/eugene/.bundler/ruby/1.9.1/rails_admin-75079da0906e/app/helpers/rails_admin/application_helper.rb:36:in
logout_path'Any help would be appreciated!