活动管理员协会未显示类别下拉列表
active admin association not showing dropdown list of category
我创建了两个模型类别和博客,其中博客有 1 个类别,类别属于博客。
现在,当我使用活动管理面板表单执行 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 注册 belongs_to:
ActiveAdmin.register Blog do
belongs_to :category, optional: true
有关详细信息,请参阅 the ActiveAdmin documentation。
我创建了两个模型类别和博客,其中博客有 1 个类别,类别属于博客。 现在,当我使用活动管理面板表单执行 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 注册 belongs_to:
ActiveAdmin.register Blog do
belongs_to :category, optional: true
有关详细信息,请参阅 the ActiveAdmin documentation。