我有一个注册应用程序,它记录一个Participant
模型,该模型有两个悬挂模型-Student_Detail
和Volunteer_Detail
。Participant
has_one
的Student_Detail
和Volunteer_Detail
。
有第三个模型Group
。Group
记录哪些参与者相互匹配。由于参与者可能涉及一个以上的Group
和Group
可能有不止一个Participant
,我认为has_and_belongs_to_many
是最佳组合Participant
和Group
。
存在一个联接表,用于Group
和Participant
我是Rails的新手,并且我使用活动管理员来管理该应用程序。
登录时,我可以看到作为资源生成的每个模型,但是我希望能够在查看Participant
选项卡时显示每个参与者的相关详细信息(学生/志愿者/小组)。当前,它仅显示仅适用于该特定模型的属性,而不适用于任何关联的模型。
这是我的模型的active_admin资源代码Participant
:
ActiveAdmin.register Participant do
permit_params :first_name, :last_name, :gender, :email, :birthdate, :phone,
:street_name, :city, :state, :zip, :role, student_details_attributes: [:nationality, :religion, :need_ride,
:has_spouse, :spouse_name, :english_level, :expectation, :length_of_stay, :exact_length, :volunteer_id,
:matched, :returned_home, :participant_id], volunteer_details_attributes: [:date, :importance, :story, :questions, :participant_id]
end
我希望能够Participant
在Active Admin中查看与表中条目相关的所有属性。目前,我只看到直接来自该模型的属性(:first_name,:last_name,:gender,:email,:birthdate,:phone,:street_name,:city,:state,:zip,:role)
让我尝试猜测,您需要显示关联的属性
show do |participant|
attributes_table do
row :id
row :full_name
attributes_table_for participant.volunteer_detail do
row :id
row :volunteer_name
end
end
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句