title: CanCan Incorrectly Denying Admin Access
body: <p>I'm working with someone else's code plus I'm rather inexperienced with Rails and i'm having an issue with CanCan &amp; Devise. </p>
  
  <p>When trying to login (using credentials I know are there as they previously worked and I've checked the DB and successfully used the reset function) I get an error screen stating.</p>
  
  <pre><code>CanCan::AccessDenied in AdminController#index
  
  You are not authorized to access this page.
  
  app/controllers/admin_controller.rb:4:in `index'
  config/initializers/quiet_assets.rb:6:in `call_with_quiet_assets'
  </code></pre>
  
  <p>and in the terminal</p>
  
  <pre><code>Started POST "/users/sign_in" for 127.0.0.1 at 2012-11-14 13:13:01 +0000
    Processing by Devise::SessionsController#create as HTML
    Parameters: {"utf8"=&gt;"✓",  "authenticity_token"=&gt;"T8CJkCIEA3r7ROiknVp/vbEgeKCBZEjl3uYd+46G7no=", "user"=&gt;{"email"=&gt;"pass@user.com", "password"=&gt;"[FILTERED]", "remember_me"=&gt;"0"}, "commit"=&gt;"Sign in"}
  WARNING: Can't verify CSRF token authenticity
    User Load (0.3ms)  SELECT `users`.* FROM `users` WHERE `users`.`email` = 'pass@user.com' LIMIT 1
  (0.2ms)  BEGIN
  (0.3ms)  UPDATE `users` SET `last_sign_in_at` = '2012-11-14 11:10:56', `current_sign_in_at` = '2012-11-14 13:13:01', `sign_in_count` = 219, `updated_at` = '2012-11-14 13:13:01' WHERE `users`.`id` = 1
  (0.1ms)  COMMIT
  Redirected to http://core.lvh.me:3000/admin
  Completed 302 Found in 355ms
  
  
  Started GET "/admin" for 127.0.0.1 at 2012-11-14 13:13:02 +0000
    Processing by AdminController#index as HTML
  Completed 500 Internal Server Error in 265ms
  
  CanCan::AccessDenied (You are not authorized to access this page.):
    app/controllers/admin_controller.rb:4:in `index'
    config/initializers/quiet_assets.rb:6:in `call_with_quiet_assets'
  </code></pre>
  
  <p>admin_controller.rb</p>
  
  <pre><code>class AdminController &lt; ApplicationController
  
    def index
     authorize! :index, :admin (#line 4)
    end
  </code></pre>
  
  <p>ability.rb</p>
  
  <pre><code>class Ability
    include CanCan::Ability
  
    def initialize(user)
      user ||= User.new # guest user (not logged in)
  
      case user.role_name
  
      when "super_admin"
        # can do everything
        can :manage, :all
  
      when "franchise_admin"
        can [:read, :search, :all, :up_down_index], Article
        can [:old_feed, :sites, :new_feed], MobileFeed
        can [:new, :read, :update], SiteSpecificArticle, site_id: user.site_id
        can [:index, :new_site_essentials], :admin
  
  
      when "franchise_editor"
        can [:new, :read, :update], SiteSpecificArticle { |ssa| ssa.site.customer.sites.include?(user.site) }
        can [:old_feed, :sites, :new_feed], MobileFeed
        can [:read, :search, :all, :up_down_index], Article
  
      when "site_admin"
        # can CRUD users for their site
        can :manage, User, site_id: user.site_id
        # can edit content for their site
        can [:read, :update], ArticleSitePermission, site_id: user.site_id
        can [:read, :update], CoreArticleSiteVisibility, site_id: user.site_id
        can [:new, :read, :update], SiteSpecificArticle, site_id: user.site_id
        can [:new, :read, :update], FrontPageCampaign, site_id: user.site_id
        can [:new, :read, :update], FrontPageTimeBasedArticle, site_id: user.site_id
        can [:new, :read, :update], FrontpageArticle, site_id: user.site_id
        can [:index, :new_site_essentials], :admin
        can [:read, :search, :all, :up_down_index, :hidden_in_this_site], Article
        can [:old_feed, :sites, :new_feed], MobileFeed
        can [:index, :create], TrackMood
        can :site_styles, Site
  
      when "editor"
        # can edit content for their site
        can [:read, :update], ArticleSitePermission, site_id: user.site_id
        can [:read, :update], CoreArticleSiteVisibility, site_id: user.site_id
        can [:new, :read, :update], SiteSpecificArticle, site_id: user.site_id
        can :manage, FrontPageCampaign, site_id: user.site_id
        can :manage, User, site_id: user.site_id
        can [:new, :read, :update], FrontPageTimeBasedArticle, site_id: user.site_id
        can [:new, :read, :update], FrontpageArticle, site_id: user.site_id
        can [:old_feed, :sites, :new_feed], MobileFeed
        can [:index, :new_site_essentials], :admin
        can [:read, :search, :all, :up_down_index, :hidden_in_this_site], Article
        can [:index, :create], TrackMood
        can :site_styles, Site
  
      else
        # guest user (not logged in)
        can [:read, :search, :up_down_index], Article
        can [:old_feed, :sites, :new_feed], MobileFeed
        can [:index, :create], TrackMood
        can :site_styles, Site
      end
    end
  end
  </code></pre>
  
  <p>Any help on this matter would be greatly appreciated. Even if it is just another step in trying to debug the issue. </p>
  
  <p>Thank you</p>