I am attempting to analyze CSV before importing into my database but am encountering a ActionDispatch::Cookies::CookieOverflow
error.
controller
def bulk_upload_weigh_ins
@response = WeighIn.check_file(params[:file])
redirect_to import_weigh_ins_path, notice: @response
end
model
def self.check_file(file)
status = {
name_error: [],
weigh_in_error: []
}
count = 0
CSV.foreach(file.path, headers: @weigh_in_cols) do |row|
hashed_row = row.to_hash
user = User.find_by(scale_id: hashed_row["scale_id"])
if user == nil
status[:name_error] << [hashed_row["name"], hashed_row["scale_id"]]
elsif user.check_ins.with_no_weigh_ins.length != 1
status[:weigh_in_error] << [hashed_row["name"], hashed_row["scale_id"]]
else
count += 1
end
status[:number_of_success] = count
end
return status
end
I've looked at this post but I'm not sure I should be using doing the same fix. Is there a better way to set this up?