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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:42:25+00:00 2026-06-04T01:42:25+00:00

I am trying to generate xml file as a background task using resque gem

  • 0

I am trying to generate xml file as a background task using resque gem here is the class which generates xml file ….

ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV']
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
require  'rubygems'
require 'builder'

class GenerateXml
  @queue = :worker

  def self.perform
    file_name = "#{Time.now.strftime('%Y_%m_%d')}_export.xml"

    xml = Builder::XmlMarkup.new(:target => file_name, :indent => 2)
    xml.instruct!(:xml, :encoding => "UTF-8")

    xml.Postings do
      Result.find_in_batches do |result|
        xml.Posting do
          xml.JobID result.job_id
          xml.JobURL result.job_url
        end
      end
    end
  end
end

and my result model from where I am extracting the fields for the xml tags is like this

require 'active_record'

class Result < ActiveRecord::Base
  def job_id
    self.link
  end

  def job_url
    self.link
  end
end

My question is why result.job_url and result.job_id from class GenerateXml is not able to map to Result class correctly?

and one more thing the Result class is under app/models directory where as GenerateXml class is under lib/jobs directory

Here is the trace of error.

      undefined method `job_id' for #<Array:0xb3f26738>

/home/netserv/RubymineProjects/crawler/lib/jobs/generate_xml.rb:22:in `perform'
/home/netserv/.rvm/gems/ruby-1.8.7-p357/gems/builder-3.0.0/lib/builder/xmlbase.rb:155:in `call'
/home/netserv/.rvm/gems/ruby-1.8.7-p357/gems/builder-3.0.0/lib/builder/xmlbase.rb:155:in `_nested_structures'
/home/netserv/.rvm/gems/ruby-1.8.7-p357/gems/builder-3.0.0/lib/builder/xmlbase.rb:63:in `method_missing'
/home/netserv/RubymineProjects/crawler/lib/jobs/generate_xml.rb:21:in `perform'
/home/netserv/.rvm/gems/ruby-1.8.7-p357/gems/activerecord-3.2.3/lib/active_record/relation/batches.rb:72:in `find_in_batches'
/home/netserv/.rvm/gems/ruby-1.8.7-p357/gems/activerecord-3.2.3/lib/active_record/querying.rb:8:in `__send__'
/home/netserv/.rvm/gems/ruby-1.8.7-p357/gems/activerecord-3.2.3/lib/active_record/querying.rb:8:in `find_in_batches'
/home/netserv/RubymineProjects/crawler/lib/jobs/generate_xml.rb:20:in `perform'
/home/netserv/.rvm/gems/ruby-1.8.7-p357/gems/builder-3.0.0/lib/builder/xmlbase.rb:155:in `call'
/home/netserv/.rvm/gems/ruby-1.8.7-p357/gems/builder-3.0.0/lib/builder/xmlbase.rb:155:in `_nested_structures'
/home/netserv/.rvm/gems/ruby-1.8.7-p357/gems/builder-3.0.0/lib/builder/xmlbase.rb:63:in `method_missing'
/home/netserv/RubymineProjects/crawler/lib/jobs/generate_xml.rb:19:in `perform'
  • 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-04T01:42:26+00:00Added an answer on June 4, 2026 at 1:42 am

    find_in_batches returns arrays. Inside the Postings block, you could do this:

      Result.find_in_batches do |results|
        results.each do
          xml.Posting do
            xml.JobID result.job_id
            xml.JobURL result.job_url
          end
        end
      end
    

    But why even bother with find_in_batches?

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

Sidebar

Related Questions

I am trying to generate an XML file using the data from a class,
I'm trying to generate a RDoc using the XML format. Here's the command that
I am trying to generate an xml file of a recipe database that has
I trying to generate an XML document which is around 23 to 30 MB,
I'm trying to generate a client using wsdl2java. The wsdl is as follows: <?xml
I have parametrized persistence.xml. I am trying to generate ddl schema using hbm2ddl. How
I am trying to generate an output XML file from a master xml file
Note, I am not trying to generate the schema for an XML file from
Im trying to load a xml file into a dataset and generate crystal report
I'm trying to generate an XML file with the my machine's hostname in some

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.