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 8364935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:32:49+00:00 2026-06-09T12:32:49+00:00

I am using rails 2.3.14 with ruby 1.8.7 and I want to download a

  • 0

I am using rails 2.3.14 with ruby 1.8.7 and I want to download a csv file without writing it to any directory.

My code:

  def export
    @news = News.find(:all, :conditions => ["updated_at >= ? and news_source_id != 1 and ready = 1", 1.week.ago])
    file_name = "Non_linksv_news_#{1.week.ago.strftime('%b-%d-%Y')}_to_#{Time.now.strftime('%b-%d-%Y')}.csv"
    File.open(file_name, "w") do |file|
      file_name << %w(Source Headline).to_csv
      @news.each { |news| file_name << [news.news_source.name, news.news_headline].to_csv }
    end
    send_file file_name
  end

It creates a file in directory then downloads. I don’t want to create file.

  • 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-06-09T12:32:50+00:00Added an answer on June 9, 2026 at 12:32 pm

    Solved

      def export
        ns = NewsSource.find_by_name 'Linksv', :select => :id
        @news = News.find(:all, :conditions => ["updated_at >= ? and news_source_id != ? and ready = 1", 1.week.ago, ns.id])
        file_name = "linksv_news_#{1.week.ago.strftime('%b-%d-%Y')}_to_#{Time.now.strftime('%b-%d-%Y')}.csv"
        csv = %w(Source Headline).to_csv
        @news.each { |news| csv << [news.news_source.name, news.news_headline].to_csv }
    
        send_data csv, :filename => file_name, :type => "text/csv"
      end
    

    It will generate csv file in proper way, with rows and columns

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

Sidebar

Related Questions

Using Rails 3.1.3 and Ruby 1.9.3. I want to give the user a list
I am using Ruby on Rails to develop a webapp. I want it so
I'd created my first web app using Ruby on Rails. And now, I want
new on ruby and using windows xp and rails 3, i want to send
I'm using Ruby on Rails and I want to display a drop down list
I'm using Ruby on Rails, and I want to know how to include a
I am building an application using Ruby on Rails. I want to do something
I'm using ruby on rails and I currently have code if level == Grad
I am using Rails 3.0, Ruby 1.9.2 and the Plataformatec simple_form gem. The code
Im using Rails 3.0.3 and ruby 1.8.7 I want to render /materials/change_prize.html.erb in materials/change_prize.js.erb

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.