[英]Active admin associated nested input
I have a rails application, that uses active admin. 我有一个Rails应用程序,使用活动管理员。 Let's say we have three entities.
假设我们有三个实体。
Student: 学生:
has_many :activities, :through => :student_activities
has_and_belongs_to_many :teams
Activity: 活动:
has_many :teams, :dependent => :destroy
Team: 球队:
belongs_to :activity
has_and_belongs_to_many :students
So on student.rb of active admin input form, I want the student to chose an activity and a team on it.: 因此,在活动管理员输入表单的student.rb上,我希望学生选择一个活动和一个团队。
form do |f|
f.inputs do
f.input :name
end
if object.new_record?
f.has_many :student_activities, allow_destroy: true do |ff|
ff.input :activity ,:input_html_options => { :class => 'chosen' }
ff.input :team ,:input_html_options => { :class => 'chosen' }
end
end
f.actions
end
My issue is that this code, show all teams. 我的问题是,此代码向所有团队展示。 not the list of teams for the chosen activity.
不是所选活动的团队列表。
So how to show teams of the activity only? 那么,如何仅向团队展示活动? based on what he choose on the :activity, and if he didn't choose the activity yet, to show him blank list.
根据他在:activity上选择的内容,如果他尚未选择活动,则向他显示空白列表。
You should use AJAX for this. 您应该为此使用AJAX。 You will have to get teams regarding on which activity you select.
您将需要就选定的活动获得团队的帮助。 After AJAX return populate dropdown and that's it.
在AJAX返回之后,填充下拉列表就是这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.