Cancan_devise_rails_admin not working

I am using mongoid, cancan, devise, rails_admin combination. each of
them works individually, however when I set an admin boolean attribute
of user, and set various places follow the tutorial, it did not work,
here is all the related code snippet:

Gemfile

gem ‘rails_admin’, :git => ‘git://github.com/sferik/rails_admin.git’
gem ‘cancan’

app/models/user.rb

class User

user.admin? works by setting the following

field :admin, type: Boolean, default: false

end

config/initializers/rails_admin.rb

RailsAdmin.config do |config|

config.authorize_with :cancan

end

app/models/ability.rb

class Ability
include CanCan::Ability
def initialize(user)
can :read, :all
if user && user.admin?
can :access, :rails_admin
end
end
end

However when I access the localhost:3000/admin, with a user with its
admin attribute set to true, I got this:

Started GET “/admin” for 127.0.0.1 at 2012-03-22 19:59:26 -0500
Processing by RailsAdmin::MainController#dashboard as HTML
MONGODB (0ms)
testapp_development[‘users’].find({:_id=>BSON::ObjectId(‘4f6932751d4ee83acb000002’)}).limit(-1).sort([[:_id,
:asc]])
Completed 500 Internal Server Error in 6ms

CanCan::AccessDenied (You are not authorized to access this page.):
cancan (1.6.7) lib/cancan/ability.rb:202:in authorize!' /home/baboonworksfine/.rvm/gems/[email protected]/bundler/gems/rails_admin-7a4fdd931f95/lib/rails_admin/extensions/cancan/authorization_adapter.rb:21:inauthorize’
activesupport (3.2.0) lib/active_support/core_ext/object/try.rb:32:in
try' (eval):4:indashboard’
actionpack (3.2.0) lib/action_controller/metal/implicit_render.rb:4:in
send_action' actionpack (3.2.0) lib/abstract_controller/base.rb:167:inprocess_action’
actionpack (3.2.0) lib/action_controller/metal/rendering.rb:10:in
`process_action’


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs