Walther H Diechmann
2008-Jun-14 23:33 UTC
[Backgroundrb-devel] does BackgrounDRB not "know" the rails environment it is running within/in parallel with?]
Hi, it probably is a noob question but I''m confused by this error message: active_support/dependencies.rb:478:in `const_missing'': uninitialized constant Invoice::ApplicationController Situation: I have an InvoicesController with a create method that in turn calls upon a MiddleMan.worker(:billing_worker), which in turn finds an Invoice and calls upon @invoice.print_invoice "public/forms/invoices/html/#{invoice.invoice_number}.html" to generate a html version of an invoice. The class Invoice.rb has this print_invoice method: def print_invoice path_and_file htmlstring = self.render_to_string "invoices/show", :layout => false File.open(path_and_file, "w+") do |f| f.puts( htmlstring) f.close end true end The self.render_to_string does look like this # Renders a record instance to a string using the provided template and additional variables. def render_to_string(template, variables={}) assigns = variables.reverse_merge(self.class.class_name.underscore.to_sym => self) self.class.render_string(template, assigns) end and the self.class.render_string looks like this # Renders a template to a string with the included variable assignments def self.render_string(template, assigns) viewer = Class.new(ApplicationController) view = Class.new(ActionView::Base) view.send(:include, viewer.master_helper_module) path = ActionController::Base.view_paths rescue ActionController::Base.view_root view.new(path, assigns, viewer).render(template) end I have a show.html.erb under app/views/invoices which holds the HTML to go with the show action on the InvoicesController. Everything is working perfectly if I open the script/console and calls invoice.print_invoice from there! However, if I hand it over to (the) MiddleMan - I''m left with the above error message! Does anybody know why the invoice.print_invoice does not work, when called in the context of billing_worker? cheers, walt class BillingWorker < BackgrounDRb::MetaWorker set_worker_name :billing_worker def create(args = nil) # this method is called, when worker is loaded for the first time logger.info "Faktura baggrundsjob startet!" end def build_invoice(invoice_id = nil) invoice = Invoice.find(invoice_id) unless invoice_id.nil? logger.info "Faktura ID #{invoice_id} skal dannes!" unless invoice.nil? result = false logger.info "Faktura ID #{invoice_id} dannes!" result = invoice.print_invoice "public/forms/invoices/html/#{invoice.invoice_number}.html" #result = %x[script/get_invoice #{invoice.id} #{invoice.invoice_number}] if result logger.info "Faktura nr #{invoice.invoice_number} blev dannet - som HTML!" result = %x[script/get_invoice_pdf #{invoice.invoice_number} #{invoice.invoice_number}] #result=false if result logger.info "Faktura nr #{invoice.invoice_number} blev dannet - som PDF!" invoice.pdf_resource = "forms/invoices/pdf/#{invoice.invoice_number}.pdf" invoice.project.invoiced= invoice.all_invoiced? invoice.project.new_contact_id=-1 # we will not be needing the find/create services of project.rb invoice.project.delivery_at_date = nil invoice.project.save logger.info "Projekt til faktura nr #{invoice.invoice_number} blev opdateret!" invoice.save invoice.invoice_items.each { |ii| Task.find(ii.task_id).update_attribute( :invoiced_at, DateTime.now) unless ii.task_id.nil? } logger.info "Faktura nr #{invoice.invoice_number} blev dannet med faktura linier!" else logger.info "Faktura med ID #{invoice_id} blev ikke dannet - som PDF!" end else logger.info "Faktura med ID #{invoice_id} blev ikke dannet - som HTML!" end else logger.info "Faktura med ID #{invoice_id} blev ikke fundet!" end end end -------------- next part -------------- An embedded message was scrubbed... From: Walther H Diechmann <walt at alco.dk> Subject: does BackgrounDRB not "know" the rails environment it is running within/in parallel with? Date: Sun, 15 Jun 2008 01:21:45 +0200 Size: 4468 URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20080615/141cea80/attachment.eml>