I have a doubt about showing a generated CSV file to the user (with a large amount of data). So here is the task I have to do.
App: I have a film that has many characters.
Task:
- allow users to upload characters via CSV (ok, done)
- if there are errors, show them for each row (ok, done)
- in the results page, also show a link to a new CSV file only with the remaining characters - the ones that couldn’t be created (I’m stuck here)
Here is part of my code (upload method):
def upload
    saved_characters = []
    characters_with_errors = []
    errors = {}
    begin
      CSV.parse(params[:csv].read, **csv_options) do |row|
        row_hash = clear_input(row.to_h)
        new_character = Character.new(row_hash)
        if new_character.save
          add_images_to(new_character, row)
          saved_characters << new_character
        else
          characters_with_errors << new_character
          errors[new_character.name] = new_character.errors.full_messages.join(', ')
        end
      end
    rescue CSV::MalformedCSVError => e
      errors = { 'General error': e.message }.merge(errors)
    end
    @upload = {
      errors: errors,
      characters: saved_characters,
      characters_with_errors: characters_with_errors
    }
  end
The issue: large amount of data
In the end, the upload.html.erb almost everything works fine, it shows the results and errors per column BUT I’m not sure how create a link on this page to send the user to the new CSV file (only with characters with errors). If the link sends the user to another method / GET endpoint (for the view with CSV format), how can I send such a large amount of data (params won’t work because they will get too long)? What would be the best practice here?
 
    