ryanb / cancan

Authorization Gem for Ruby on Rails.
MIT License
6.26k stars 783 forks source link

uninitialized constant Dashboard, Main, etc... #950

Open redrick opened 11 years ago

redrick commented 11 years ago

Hi guys,

I got this annoying thing going on in my app, I thought that its the mistake of gems I am using, but turns out it got to be cancan.. here is my situation as I wrote already in the mistake for activeadmin

I rewrote my app into rails (not rails-api anymore), I am using few models, so I rewrote current_ability method like this:

def current_ability
  ability_class = (controller_name.classify + 'Ability').classify.constantize

  @current_ability ||= ability_class.new(current_user)
end

which works perfectly for the application, where i got on the level of models ability folder and there are included all my abilities including Application ability:

class ApplicationAbility

  ### includes
  include CanCan::Ability

  ### public
  def initialize(user)
    user ||= User.new

    can :manage, :all
  end
end

all other abilities inherit from this one...

and now my problem is that I need some admin, because this is just REST API so its not HTML heavy, therefore with every change I got to go to database and make mess there through mysql workbench or some such tool...

so I chose activeadmin to do this stuff, but after instal and all I just got the message as I linked from acitve admin"

NameError in Admin::DashboardController#index
uninitialized constant Dashboard

So after some talks with people over there I chose to switch to rails_admin, so I would have no problems, but I got exactly the same problem, but this time its not dashboard but Main

After looking into application controller I got the load_and_authorize_resource there, if I comment it out, everything goes as expected, but after adding it back, all things fall apart and throw error again...

I found out that as long as I supply the load_and_authorize_resource in every other controller that inherits from application one but not to the application one it works just fine... but i got kinda bigg app and maintaining this line in all files seems kinda dull when i can put it into one all inherit from....

please dont you people have some solution for this kind of situation ? thx for you time :)

dannio commented 10 years ago

I believe it's due to the fact you don't have a model for that controller? If you don't have a model backed controller, you can't use load_and_authorize_resource, but intead call: authorize_resource :class => false

xhoy commented 10 years ago

Thanks for your submission! The ryanb/cancan repository has been inactive since Sep 06, 2013. Since only Ryan himself has commit permissions, the CanCan project is on a standstill.

CanCan has many open issues, including missing support for Rails 4. To keep CanCan alive, an active fork exists at cancancommunity/cancancan. The new gem is cancancan. More info is available at #994.

If your pull request or issue is still applicable, it would be really appreciated if you resubmit it to CanCanCan.

We hope to see you on the other side!