diff --git a/app/controllers/mat_assignment_rules_controller.rb b/app/controllers/mat_assignment_rules_controller.rb index b8e02eb..f9e831f 100644 --- a/app/controllers/mat_assignment_rules_controller.rb +++ b/app/controllers/mat_assignment_rules_controller.rb @@ -59,22 +59,22 @@ class MatAssignmentRulesController < ApplicationController end def mat_assignment_rule_params - # Set defaults to empty arrays if no checkboxes are selected - # otherwise rails interprets this as "don't modify" + # Ensure defaults to empty arrays for checkboxes params[:mat_assignment_rule][:weight_classes] ||= [] params[:mat_assignment_rule][:bracket_positions] ||= [] params[:mat_assignment_rule][:rounds] ||= [] - # Permit the parameters and convert specific fields to integer arrays + # Permit parameters and normalize types params.require(:mat_assignment_rule).permit(:mat_id, weight_classes: [], bracket_positions: [], rounds: []).tap do |whitelisted| whitelisted[:weight_classes] = whitelisted[:weight_classes].map(&:to_i) whitelisted[:rounds] = whitelisted[:rounds].map(&:to_i) + whitelisted[:bracket_positions] = whitelisted[:bracket_positions] # Assume these are strings end end # Load data needed for the form def load_form_data - @available_mats = Mat.all + @available_mats = @tournament.mats @unique_bracket_positions = @tournament.matches.select(:bracket_position).distinct.pluck(:bracket_position) @unique_rounds = @tournament.matches.select(:round).distinct.pluck(:round) end diff --git a/app/views/mat_assignment_rules/_form.html.erb b/app/views/mat_assignment_rules/_form.html.erb index 7f47317..d917d23 100644 --- a/app/views/mat_assignment_rules/_form.html.erb +++ b/app/views/mat_assignment_rules/_form.html.erb @@ -15,7 +15,7 @@ <% if @tournament.weights.any? %> <% @tournament.weights.each do |weight| %>
- <%= check_box_tag "mat_assignment_rule[weight_classes][]", weight.id, @mat_assignment_rule.weight_classes.include?(weight.id) %> + <%= check_box_tag "mat_assignment_rule[weight_classes][]", weight.id, @mat_assignment_rule.weight_classes.map(&:to_i).include?(weight.id) %> <%= label_tag "mat_assignment_rule_weight_classes_#{weight.id}", weight.max %>
<% end %> @@ -45,7 +45,7 @@ <% if @unique_rounds.present? %> <% @unique_rounds.each do |round| %>
- <%= check_box_tag "mat_assignment_rule[rounds][]", round, @mat_assignment_rule.rounds.include?(round) %> + <%= check_box_tag "mat_assignment_rule[rounds][]", round, @mat_assignment_rule.rounds.map(&:to_i).include?(round) %> <%= label_tag "mat_assignment_rule_rounds_#{round}", round %>
<% end %> @@ -56,6 +56,6 @@
- <%= form.submit 'Submit', :class=>"btn btn-success" %> + <%= form.submit 'Submit', class: "btn btn-success" %>
<% end %>