活动管理员关联未显示类别的下拉列表



我创建了两个模型Category和Blog,其中博客有一个类别,类别属于博客。现在,当我使用活动的管理面板表单来执行crud操作时,博客表单不会显示带有类别选项的下拉列表

Blog model
class Blog < ApplicationRecord
has_one :category
has_one_attached :image
end
category model
class Category < ApplicationRecord
belongs_to :blog
attr_accessor :category_type
end
admin/blog.rb
ActiveAdmin.register Blog do
# ent all parameters which should be permitted for assignment
#
permit_params :title, :*********, :******, :category_id, :*****, :*********
#
index do
selectable_column
id_column
column :title
column :******
column :******
column :category_id
column :*****
column :*****
actions
end
]
form do |f|
f.inputs do
f.input :title
f.input :********
f.input :*******
f.input :category_id
f.input :******
f.input :image, as: :file
end
f.actions
end
end

有什么解决方案或修正方案吗?

除了ActiveRecord关系之外,您还需要向ActiveAdmin:注册以下内容

ActiveAdmin.register Blog do
belongs_to :category, optional: true

有关更多详细信息,请参阅ActiveAdmin文档。

最新更新