cancancan

  1. https://github.com/ryanb/cancan/wiki/authorizing-controller-actions

when using load_and_authorize_resource cancancan tries to guess resource class based on controller name.

but if they differ cancancan will fail to find resource class and will prevent controller from rendering a view - silently!

app/models/billing/accounting_act.rb:

class AccountingAct
  ...
end

app/controllers/billing/accounting_acts_controller.rb:

class Billing::AccountingActsController
  load_and_authorize_resource
  ...
end

in this case CanCanCan will try to load Billing::AccountingAct resource but will not raise any errors when it doesn’t find appropriate model.

to fix it specify resource name explicitly:

app/controllers/billing/accounting_acts_controller.rb:

class Billing::AccountingActsController
  load_resource :accounting_act
  authorize_resource
  ...
end