Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4090660
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:16:00+00:00 2026-05-20T19:16:00+00:00

I have a Rails 3 app which when a download link is clicked on

  • 0

I have a Rails 3 app which when a download link is clicked on the client an ajax request is made to the server to dynamically generate a file and send it back. The server tells me the file is being sent:

Sent data test.csv (1.4ms)

but the browser isn’t prompting me to download the file. When I inspect the ajax request I see the data coming back in the response. Any help getting the browser to prompt the user to download the file would be appreciated. Below is my code:

Here’s my controller:

def generate_file
  list = List.find(params[:id])
  file = ''
  list.contacts.all.each do |contact|
    file << contact.firstname + ',' + contact.lastname + '\n'
  end
  send_data file, :filename => list.name + '.csv', :type => 'text/csv'
end

Here’s my client side code:

$j('.download').click(function() {
  var id = $j(this).attr("id");
  $j.ajax({
   type: "POST",
   url: "/lists/" + id + "/generate_file"
 });
});

Here’s my routes.rb

resources :contacts
resources :lists do
   member do 
     post 'generate_file'
   end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:16:01+00:00Added an answer on May 20, 2026 at 7:16 pm

    Sending files over ajax doesn’t work as easily as you might hope. You’re probably better off not using ajax and just using a regular HTTP request unless it’s important to use ajax for some reason.

    There is a good answer to a similar question here: How do you invoke a file download with link_to_remote in rails?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an rails app which redirects wrong urls to /. I made 404.html
I have rails app which are working perfectly in the local computer. But when
So I have a Rails app (which in this case seems like it would
I have a Rails 3.1.3 app which uses devise for users authentication and soft-deletes
I have a rails app running on passenger standalone, which is working perfectly. I
I have got Sinatra/Rails app and an action which starts some long process. Ordinary
I have a JavaScript widget which communicates with my Rails app by creating tags
In a Ruby on Rails app, we have some details which are stored as
I have rails app which has a list of users. I have different relations
i have a rails app which makes heavy use of activeresource and httparty to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.