Гем CanCanCan, не работает без модели

Добавляю роли в приложении, все работает ок, кроме одного: У меня есть Warehouse_manager, у него есть свои права в приложении:

  Ability.rb

  class Ability
    include CanCan::Ability

    def initialize(user)
      return unless user

      can :manage, User, id: user.id
      send(user.role)
    end

    private

  def admin
    can :manage, :all
  end

  def manager
    can :manage, :all
    cannot :manage, Transfer
    cannot :manage, Organization
    cannot :manage, Warehouse
    cannot :manage, User
  end

  def warehouse_manager
    cannot :manage, :all
    can :manage, Transfer
    can :manage, Warehouse
    can :read, :supply
  end`

Controller supplies_controller.rb

class Admin::SuppliesController < Admin::ApplicationController
  load_and_authorize_resource :class => false
  before_action :set_supply, only: %i[show]
  

  def index
    @supplies = Order.supplies
                     .page(params[:page])
                     .per(Order::PER_PAGE_RECORDS)
  end

Модель Supply.rb отсутствует Поэтому CanCanCan может только показать страницу, а при нажатии кнопки "Добавить" вылетает ошибка у всех юзеров NoMethodError at /admin/supplies/new undefined method `new' for :supply:Symbol Did you mean? next

module CanCan
  module ControllerResourceBuilder
    protected
    def build_resource
      resource = resource_base.new(resource_params || {})
      assign_attributes(resource)
    end
    def assign_attributes(resource)
      resource.send("#{parent_name}=", parent_resource) if @options[:singleton] && parent_resource

Пробовал так

  def warehouse_manager
    cannot :manage, :all
    can :manage, Transfer
    can :manage, Warehouse
    can :read, Supply
  end`

Не работает, перечитал всю доку по CanCanCan решение не могу найти.


Ответы (0 шт):