SpeciesFileGroup/taxonworks

View on GitHub
lib/generators/taxonworks/batch_load/templates/actions.tt

Summary

Maintainability
Test Coverage

# UNCOMMENT THIS IF IT DOESN'T ALREADY EXIST
# def batch_load
# end

# TODO: AUTOGENERATED STUB, check and update
def preview_<%= batch_loader_name %>_batch_load 
  if params[:file] 
    @result = <%= full_interpreter_class %>.new(batch_params)
    digest_cookie(params[:file].tempfile, :<%= cookie_name %>)
    render '<%= table_name %>/batch_load/<%= batch_loader_name %>/preview'
  else
    flash[:notice] = "No file provided!"
    redirect_to action: :batch_load 
  end
end

# TODO: AUTOGENERATED STUB, check and update
def create_<%= batch_loader_name %>_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :<%= cookie_name %>)
    @result = <%= full_interpreter_class %>.new(batch_params)
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} TODO RECORD TYPES were created."
      render '<%= table_name %>/batch_load/<%= batch_loader_name %>/create' and return
    else
      flash[:alert] = 'Batch import failed.'
    end
  else
    flash[:alert] = 'File to batch upload must be supplied.'
  end
  render :batch_load
end