Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Frontend Handling: FILES/CSV with Rails API

I have a Rails API endpoint which sends a csv file on API request:

def download_csv

    headers = ['column one', 'column two', 'column three']

    csv_data = CSV.generate(headers: true) do |csv|
      csv << headers
      csv << ["A", "B", "C"]
    end
    csv_data.strip

    send_data(
      csv_data,
      filename: 'attachment.csv',
      type: :csv,
      disposition: 'attachment; attachment.csv',
    )
  end

Problem:

When i hit the endpoint, it returns a 200, however my browser isn't downloading the file...

Note that i am running a Rails API server so I don't have any views only Mode controller and services.

my frontend code looks like this:

 <Button 
        onClick={() => {
          return API.downloadUserCsv().then(() => {
            Modal.alert({ body: 'Success' })
          })
        }}
      >
        Download CSV
      </Button>
downloadUserCsv(): Promise<AxiosResponse> {
    return this.http.get(`/admin/debug/users/download_csv`)
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Found the solution.

<Button 
   onClick={() => {window.open(your backend url)})
>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!