2

I have a engine inside the lib folder named Support. In that folder, I have a Ticket controller.

I have created an ability class in the main app and I'm trying to manage all the models for the admin role. When I call the Tickets controller, it throws the error:

NameError in Support::TicketsController#index uninitialized constant Ticket

The app/model/ability.rb file is:

class Ability 
  include CanCan::Ability

  def initialize(user)
    user ||= User.new
    if user.role? == :admin
      can :manage , :all
    end
  end
end

The lib/support/tickets_controller.rb file is:

module Support
  class TicketsController < Support::ApplicationController
    load_and_authorize_resource
    respond_to :html, :xml, :json

    def index
    end
  end
end
4

1 に答える 1

0

If the model class is namespaced differently than the controller, you will need to specify the :class option.

module Support
  class TicketsController < ApplicationController
    load_and_authorize_resource :class => Support::Ticket
  end
end
于 2012-08-22T08:33:52.170 に答える