【发布时间】:2019-12-12 10:34:04
【问题描述】:
我正在尝试调整表格,以便当顶部“比赛”collection_select 的值发生更改时,“主队”和“客队”的可用值会更改为仅显示该比赛中的那些球队(即比赛.团队)。该应用程序本身正在按我的预期工作,这只是我想添加的东西以提高可用性。
我一直在阅读有关此问题的多篇文章,所有文章都建议使用 Javascript/AJAX(不是我的强项),但在路由、控制器、部分等方面似乎有不同的方法。
任何可以提供的指针或帮助将不胜感激!
_form.html.erb:
<div class="col-md-6 offset-md-3">
<%= form_for(@game, url: yield(:form_url)) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="form-group">
<%= f.label :competition, class: 'control-label' %>
<%= f.collection_select :competition_id, Competition.order(:name),:opta_id,:name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :home_team_id, class: 'control-label' %>
<%= f.collection_select :home_team_id, Team.order(:name),:opta_id,:name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :away_team_id, class: 'control-label' %>
<%= f.collection_select :away_team_id, Team.order(:name),:opta_id,:name, class: 'form-control' %>
</div>
<%= f.submit yield(:button_text), class: "btn btn-primary" %>
<% end %>
</div>
【问题讨论】: