Skip to content

Instantly share code, notes, and snippets.

@rShetty
Created October 14, 2014 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rShetty/c47e1d96698b0e46a3b5 to your computer and use it in GitHub Desktop.
Save rShetty/c47e1d96698b0e46a3b5 to your computer and use it in GitHub Desktop.
def create
uploaded_file = params[:batch_payouts_csv]
unless valid_file_type?(uploaded_file)
render json: {"error_message" => I18n.t("merchant.messages.errors.invalid_file_type")}, status: 400
return
end
uploaded_csv_file = Batch::CsvFile.new(uploaded_file.path)
unless uploaded_csv_file.valid_size?
render json: {"error_message" => I18n.t("merchant.messages.errors.exceeding_file_size")}, status: 400
return
end
filename_with_timestamp = "#{DateTime.now.strftime("%Q")}_#{uploaded_file.original_filename}"
merchant_employee = @current_user
currency = Currency.find(batch_payout_params[:currency_id])
batch_payout = BatchPayout.create(merchant_employee: merchant_employee, currency: currency)
unless request.xhr?
response = {filename: filename_with_timestamp, status: "success", location: merchants_batch_payouts_path(batch_payout)}
render text: response.to_json, status: 201 \
return
end
render json: {"filename" => filename_with_timestamp}, location: merchants_batch_payouts_path(batch_payout), status: 201
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment