【问题标题】:wrong argument type Class (expected Module) Rails 5 splitting up routes错误的参数类型类(预期的模块)Rails 5 拆分路线
【发布时间】:2021-07-19 17:01:12
【问题描述】:

正如标题所暗示的,我正在拆分我的路由文件,我有 7 个拆分文件,前 6 个工作和路由已扩展到这些文件,但是,由于某种原因,其中一个文件不起作用。

这就是我所拥有的

routes.rb

Rails.application.routes.draw do
  ..
  extend Crm # works
  extend Customers # works
  extend Suppliers # works
  extend Employees # works
  extend Bank # doesn't work
  extend Accounts # works
  extend Admin # works
  ..
end

config/routes/bank.rb 文件中有以下内容

module Bank
  def self.extended(router)
    router.instance_exec do
      # bank routes
      resources :bank_accounts, except: %i[destory] do
        member do
          get :import_transactions
          get :reconcile
          post :process_reconcile
        end

        collection do
          get :list
          post :import_transactions_confirm
          post :process_import_transactions_confirm
          get :transfer
          post :process_transfer
          get :revalue_currency_bank_account
          post :process_revalue_currency_bank_account
        end
      end
    end
  end
end

这是所有其他文件的相同布局,所以我不确定为什么这个文件会导致错误。 我得到的错误是

wrong argument type Class (expected Module)

【问题讨论】:

    标签: ruby-on-rails ruby model-view-controller routes


    【解决方案1】:

    Bank 只能定义一次,可以是classmodule。你可能已经在你的应用程序的其他地方有一个Bank 类。如果您暂时删除 extend Bank 行,请进入 Rails 控制台并检查:

    Bank.class
    

    如果返回Class,则意味着您的应用已经将Bank 定义为一个类。你需要为你的路由选择一个不同的模块名称,比如Banks

    module Banks
      def self.extended(router)
        ...
    

    【讨论】:

    • 知道了,是的,它返回了课程,感谢您的快速回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 2012-01-13
    • 2019-08-28
    • 1970-01-01
    • 2015-07-14
    • 1970-01-01
    相关资源
    最近更新 更多