ActiveAdmin中的多态单例

时间:2019-03-13 10:34:30

标签: ruby-on-rails singleton activeadmin polymorphic-associations

我具有以下数据结构:

class BankAccount < ApplicationRecord
  belongs_to :bankable, polymorphic: true
end

class Buyer < ApplicationRecord
  has_one  :bank_account, as: :bankable
end

class Vendor < ApplicationRecord
  has_one  :bank_account, as: :bankable
end

我在routes.rb中定义了其他路由:

namespace :admin do
  resources :buyers do
    resource :bank_account
  end
  resources :vendors do
    resource :bank_account
  end
end

我的ActiveAdmin是:

ActiveAdmin.register BankAccount do
  actions :all, except: [:index, :destroy]

  controller do
    defaults singleton: true
    belongs_to :buyer, :vendor, polymorphic: true
  end
end

但是当尝试通过bank_account创建新的admin/buyers/1/bank_account/new时,

我遇到以下错误:

No route matches {:action=>"index", :buyer_id=>"1", :controller=>"admin/bank_accounts"}

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

如评论中所述,将resource :bank_account更改为resources :bank_account。修改之后,您可以在控制台中运行命令rails routes/rake routes并检查所需的路由是否出现。