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 … &
For what it’s worth, this is what I did, bypassing
render_to_streamentirely. This is in /lib or app/classes (addingconfig.autoload_paths += %W(#{config.root}/classesinto config/application.rb):#classes/bookreport.rb
#app/classes/onixtwo.rb
Called from the view like this:
Via a controller like this: