问题描述
我在Active Admin中存在一个嵌套资源创建页面的问题,该页面中的父级(“人”)具有基于“主题”出现的不同子级“意见”。观点是联接表,每个观点都属于一个人和一个主题。
我确实有可以单独添加的嵌套资源,这很棒(“添加新意见”按钮,您可以从中从其所属的下拉列表中进行选择),但是想法是,意见的字段每个主题已经出现,只需填写即可。如果未填写该意见,则仍会实例化该意见,但视图中有条件说“对该主题没有特定意见”。我希望每次客户创建新人员时(尽可能多地查看要填写的所有主题和意见),使管理面板尽可能易于管理。
class Person < ApplicationRecord
has_many :opinions,dependent: :destroy
has_many :topics,through: :opinions
accepts_nested_attributes_for :opinions
end
class Opinion < ApplicationRecord
belongs_to :person,optional: true
belongs_to :theme
end
class Topic < ApplicationRecord
has_many :opinions,dependent: :destroy
has_one_attached :photo
end
ActiveAdmin.register Person do
permit_params :name,:description,:photo,opinions_attributes: [:id,:content,:topic_id]
form do |f|
f.inputs 'Details' do
f.input :name
f.input :description
f.input :photo,as: :file,label: "logo"
end
f.inputs "Opinions" do
f.has_many :opinions,allow_destroy: true,heading: nil,new_record: true do |a|
a.input :topic,as: :select,collection: Thematique.all.map { |u| [u.titre,u.id] },include_blank: false
# Although I would like to get rid of the line above by already having the association of each opinion to each topic or make it hidden
a.input :content
end
end
f.actions
end
end
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)