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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:40:27+00:00 2026-06-02T21:40:27+00:00

Introduction I have a app that has multiple tables, some with and some without

  • 0

Introduction

I have a app that has multiple tables, some with and some without associations.

Some tables will be required to hold around 100,000 entries.

The app is using Rails 3.2 on Ruby 1.9 and hosted on Heroku. I have access to workers if needed.

The Requirement in Question

A vital requirement for the app is to allow users to export the data as a CSV – a requirement for this is to allow the user to filter what data they want to export but I am not worrying about that at the moment as you will see from the data below, I have hard-coded what data is to be exported but this does rule out creating a rake task to just export the whole table.

Also the method implemented must be factored to allow to be used by multiple tables to avoid unnessaccery code repeating.

Current Solution

I am implementing delayed_job in my app and performing a CSV generate in a job. While doing this I am following the solution found here at http://www.ayokasystems.com/blog/delegating-long-running-jobs-in-rails/ from ‘abdullah’.

The idea being is to generate the data in CSV format and save it in a LONGTEXT field in the UserJobs table to allow the user to download once complete and at a future time.

The Problem

The method used from the above tutorial works fine in my app until I run a job of 100,000 records at once. To overcome this I have tried to add the cool find_each function to the perform method but delayed job worker reports back a error everytime it tries to process it:

[Worker(host:*** pid:18637)] ReportJob failed with NoMethodError: undefined method `each' for #<Title:0x007ff20c1ec1b0> - 0 failed attempts
[Worker(host:*** pid:18637)] ReportJob failed with NoMethodError: undefined method `each' for #<Title:0x007ff20ec47f18> - 1 failed attempts
[Worker(host:*** pid:18637)] 2 jobs processed at 10.5219 j/s, 2 failed ... 

My code for the perform method is:

def perform
  Title.find_each do |titles|
    csv_data = CSV.generate do |csv|
      titles.each do |t|
        csv << t.to_csv
      end
    end
    user_job = UserJob.find(user_job_id)
    user_job.update_attribute :data, csv_data
  end
end

Can anyone see what the issue could be, I am thinking I have just made a stupid mistake with how I am looping through things.

I am very open to any other suggestions to how to accomplish the requirement in question but please bear in mind the limitations I have with Heroku.

  • 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-02T21:40:32+00:00Added an answer on June 2, 2026 at 9:40 pm

    You are trying to iterate with each but titles in this case are instances of title (not array).

    csv_vals = []
    columns = [:name, :release_date, :studio]
    
    Title.find_each(:select => columns) do |title| 
      columns.each {|value| csv_vals << "#{title[value]}"}
    end
    
    # comma separated string 
    csv_string = csv_vals.join(',')
    

    There is more elegant way to formulate CSV string but I am too lazy to experiment.

    What is important is that you are doing SELECT only on columns you need. For 100 000 records that adds to a lot of less bandwidth DB communication. With just find_each you get all columns for each row and you don’t need them.

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

Sidebar

Related Questions

Introduction I have some sort of values that I might want to access several
The usual case. I have a simple app that will allow people to upload
Introduction I have been so annoyed by applications that have a startup dialog which
Just an introduction of my code... I have a view that consists of -details
My application has a collection of around 1940 icons that are used throughout. They're
I have an app that is displaying a webpage using a WebView control. I
I have followed the tutorial: Introduction-to-in-app-purchases I think I have everything done exactly how
Introduction Google chrome has a feature that allows you to create shortcuts to web
The problem I'm running into the typical virtual-directory dilemma in that you have some
INTRODUCTION : I have a function(callback) that receives a object as an argument, inside

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.