我具有以下数据结构:
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"}
感谢您的帮助!
答案 0 :(得分:0)
如评论中所述,将resource :bank_account
更改为resources :bank_account
。修改之后,您可以在控制台中运行命令rails routes/rake routes
并检查所需的路由是否出现。