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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:23:09+00:00 2026-06-04T10:23:09+00:00

This method works OK, but if I add delayed_job’s handle_asychronously, I get can’t convert

  • 0

This method works OK, but if I add delayed_job’s handle_asychronously, I get can't convert nil into String:

  def onixtwo 
        s = render_to_string(:template=>"isbns/onix.xml.builder") 
        send_data(s, :type=>"text/xml",:filename => "onix2.1.xml")
  end
     handle_asynchronously :onixtwo

So rendering with delayed job is clearly having a problem with params being passed. I’ve tried putting this job in a rake task but render_to_string is a controller action – and I’m using a current_user variable which needs to be referenced in the controller or view only. So… what’s the best way to delay a rendering job?

/////////update////////

Given that I’m currently pair-programming with a toddler, I don’t have the free hands to investigate additional class methods as wisely recommended in the comments – so as a quick and dirty I tried this:

  def onixtwo 

   system "  s = render_to_string(:template=>'isbns/onix.xml.builder') ; send_data(s, :type=>'text/xml',:filename => 'onix2.1.xml') & "
   redirect_to isbns_path, :target => "_blank", :flash => { :success => "ONIX message being generated in the background." }

end

Why doesn’t it work? No error message just no file produced – which is the case when I remove system … &

  • 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-04T10:23:12+00:00Added an answer on June 4, 2026 at 10:23 am

    For what it’s worth, this is what I did, bypassing render_to_stream entirely. This is in /lib or app/classes (adding config.autoload_paths += %W(#{config.root}/classes into config/application.rb):

    #classes/bookreport.rb

    # -*- encoding : utf-8 -*-
    require 'delayed_job'
    require 'delayed/tasks'
    
    class Bookreport
    
      # This method takes args from the book report controller. First it sets the current period. Then it sorts out which report wants calling. Then it sends on the arguments to the correct class. 
      def initialize(method_name, client, user, books)
        current_period  = Period.where(["currentperiod = ? and client_id = ?", true, client]).first
        get_class       = method_name.capitalize.constantize.new
        get_class.send(method_name.to_sym, client, user, books.to_a, current_period.enddate)
      end
    end
    

    #app/classes/onixtwo.rb

    require 'builder'
    
    class Onixtwo
    
      def onixtwo(client_id, user_id, books, enddate)
    
      report_name       = "#{Client.find_by_id(client_id).client_name}-#{Time.now}-onix-21"
      filename          = "#{Rails.root}/public/#{report_name}.xml"
      current_company   = Company.where(:client_id => client_id).first
    
      File.open(filename, "w") do |file|
    
        xml = ::Builder::XmlMarkup.new(:target => file, :indent => 2)
        xml.instruct!(:xml, :version => "1.0", :encoding => "utf-8")
        xml.declare! :DOCTYPE, :ONIXMessage, :SYSTEM, "http://www.editeur.org/onix/2.1/03/reference/onix-international.dtd"
        xml.ONIXMessage do
          xml.Header do
           #masses of Builder code goes here...
        end
      end #of file
      xmlfile = File.open(filename, "r")
      onx     = Onixarchive.new(:client_id => client_id, :user_id => user_id)
      onx.xml = xmlfile
      onx.save!
    
    end #of method
    handle_asynchronously :onixtwo
    
    end #of class
    

    Called from the view like this:

        = link_to("Export to ONIX 2.1", params.merge({:controller=>"bookreports"  , :action=>:new, :method_name => "onixtwo"}))
    

    Via a controller like this:

    class Books::BookreportsController < ApplicationController
    #uses Ransack for search, hence the @q variable
      def new 
        @q              = Book.search(params[:q])
        @books          = @q.result.order('pub_date DESC')      
        method_name     = params[:method_name]
        Bookreport.new(method_name, @client, @user, @books)
        redirect_to books_path, :flash => {:success => t("#{method_name.to_sym}").html_safe}
      end
    
    end 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't seem to get this toString() method to work? The deepToString method works
I found out this morning that proc.new works in a class initialize method, but
I can't figure out why this is. I have a connect method that works
Can this method work? public String sayHello(){ return Hello.jsp?name= + laala; } I am
How can I improve this method so that it works with multiple tables? public
I'm trying to run this method, it works fine but every time after some
This method works, but it works very slowly. I think one of the problems
This code works fine in C#: Expression.Lambda(LambdaBody); But none of the methods for building
This method works as expected - it creates a JTree with a root node
I am having trouble constructing a jqGrid TreeGrid using local data. This method works

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.