ryanb/cancan — Issue #568: CanCan 1.6.7: Admin Namespaced 'authorize_resource(:class => false)' failure
Author: bsodmike
Created: 2012-03-02 13:30:22+00:00
State: open

Since [I couldn't get this to work with CanCan 2.0](https://github.com/ryanb/cancan/issues/565), I decided to rvt back to CanCan 1.6.7

My setup is quite similar and is as follows:

```ruby
namespace :admin do
root :to => 'dashboard#index'
```
#### admin_controller.rb
```ruby
class AdminController < ApplicationController
before_filter :authenticate_user!
before_filter do
flash[:error] = "Unauthorised Access Denied!" unless current_user && current_user.admin?
redirect_to '/' unless current_user && current_user.admin?
end

check_authorization
def current_ability
@current_ability ||= AdminAbility.new(current_user)
end
end
```

#### admin/dashboard_controller.rb
```ruby
class Admin::DashboardController < AdminController
authorize_resource(:class => false)

# ...

end
```

#### models/admin_ability.rb
```ruby
class AdminAbility
include CanCan::Ability
def initialize(user)
# define admin abilities here ....
can :manage, "admin/dashboard"
can :read, "admin/dashboard"
end
end
```

Looking at `params[:controller]` in the exception raised by CanCan it's showing it as `admin/dashboard`, however, I'm still getting

```ruby
CanCan::AccessDenied in Admin::DashboardController#index
You are not authorized to access this page.
```

This is quite perplexing...