1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-24 17:04:43 +00:00

Fixed mat assignment rules. MySQL required implicit conversion to an integer.

This commit is contained in:
2025-01-12 08:15:45 -05:00
parent e612a4b10e
commit c45ec8ab38
2 changed files with 7 additions and 7 deletions

View File

@@ -59,22 +59,22 @@ class MatAssignmentRulesController < ApplicationController
end end
def mat_assignment_rule_params def mat_assignment_rule_params
# Set defaults to empty arrays if no checkboxes are selected # Ensure defaults to empty arrays for checkboxes
# otherwise rails interprets this as "don't modify"
params[:mat_assignment_rule][:weight_classes] ||= [] params[:mat_assignment_rule][:weight_classes] ||= []
params[:mat_assignment_rule][:bracket_positions] ||= [] params[:mat_assignment_rule][:bracket_positions] ||= []
params[:mat_assignment_rule][:rounds] ||= [] 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| 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[:weight_classes] = whitelisted[:weight_classes].map(&:to_i)
whitelisted[:rounds] = whitelisted[:rounds].map(&:to_i) whitelisted[:rounds] = whitelisted[:rounds].map(&:to_i)
whitelisted[:bracket_positions] = whitelisted[:bracket_positions] # Assume these are strings
end end
end end
# Load data needed for the form # Load data needed for the form
def load_form_data 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_bracket_positions = @tournament.matches.select(:bracket_position).distinct.pluck(:bracket_position)
@unique_rounds = @tournament.matches.select(:round).distinct.pluck(:round) @unique_rounds = @tournament.matches.select(:round).distinct.pluck(:round)
end end

View File

@@ -15,7 +15,7 @@
<% if @tournament.weights.any? %> <% if @tournament.weights.any? %>
<% @tournament.weights.each do |weight| %> <% @tournament.weights.each do |weight| %>
<div> <div>
<%= 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 %> <%= label_tag "mat_assignment_rule_weight_classes_#{weight.id}", weight.max %>
</div> </div>
<% end %> <% end %>
@@ -45,7 +45,7 @@
<% if @unique_rounds.present? %> <% if @unique_rounds.present? %>
<% @unique_rounds.each do |round| %> <% @unique_rounds.each do |round| %>
<div> <div>
<%= 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 %> <%= label_tag "mat_assignment_rule_rounds_#{round}", round %>
</div> </div>
<% end %> <% end %>
@@ -56,6 +56,6 @@
<!-- Submit Button --> <!-- Submit Button -->
<div> <div>
<%= form.submit 'Submit', :class=>"btn btn-success" %> <%= form.submit 'Submit', class: "btn btn-success" %>
</div> </div>
<% end %> <% end %>