Fix CSV import & contestant deletion
This commit is contained in:
parent
f78a082ad3
commit
4645b45f5d
@ -92,9 +92,10 @@ class ContestantsController < ApplicationController
|
||||
@content.each_with_index do |row, i|
|
||||
if all_params["row_#{i}".to_sym] == "1"
|
||||
if @form.email_column == -1
|
||||
Contestant.create(name: row[@form.name_column], contest: @contest)
|
||||
Contestant.create(name: row[@form.name_column], contest: @contest, time_seconds: 0)
|
||||
else
|
||||
Contestant.create(name: row[@form.name_column], email: row[@form.email_column], contest: @contest)
|
||||
logger.info("Email")
|
||||
Contestant.create(name: row[@form.name_column], email: row[@form.email_column], contest: @contest, time_seconds: 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -21,7 +21,7 @@
|
||||
#
|
||||
class Contestant < ApplicationRecord
|
||||
belongs_to :contest
|
||||
has_many :completions
|
||||
has_many :completions, dependent: :destroy
|
||||
|
||||
before_create :initialize_time_seconds
|
||||
|
||||
|
@ -32,7 +32,7 @@ class CsvImport < ApplicationRecord
|
||||
end
|
||||
|
||||
begin
|
||||
csv = CSV.read(attachment_changes["file"].attachable.path, col_sep: separator)
|
||||
csv = CSV.read(attachment_changes["file"].attachable.path, col_sep: separator_for_database)
|
||||
|
||||
errors.add(:file, :empty) if csv.count < 1 || (csv.count == 1 && csv[0].count == 1 && csv[0][0] == "")
|
||||
rescue CSV::MalformedCSVError => e
|
||||
|
@ -14,6 +14,10 @@
|
||||
= form.label :email_column
|
||||
= t("contestants.import.email_column")
|
||||
|
||||
.row.mb-3
|
||||
.col
|
||||
= form.submit t("helpers.buttons.confirm"), class: "btn btn-primary"
|
||||
|
||||
.row.g-3
|
||||
.col
|
||||
table.table.table-striped.table-hover
|
||||
@ -33,8 +37,4 @@
|
||||
td
|
||||
.form-check.form-switch
|
||||
= form.check_box "row_#{i}".to_sym, class: "form-check-input", checked: true
|
||||
|
||||
.row.g-3
|
||||
.col
|
||||
= form.submit t("helpers.buttons.confirm"), class: "btn btn-primary"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user