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/ruby-1.9.3-p0@rails320/bundler/gems/rails_admin-7a4fdd931f95/lib/rails_admin/extensions/cancan/authorization_adapter.rb:21:in
`authorize''
activesupport (3.2.0) lib/active_support/core_ext/object/try.rb:32:in
`try''
(eval):4:in `dashboard''
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:in
`process_action''
actionpack (3.2.0) lib/action_controller/metal/rendering.rb:10:in
`process_action''
...
...
...
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.