Integrate Jasper in Rails 3

I am trying to integrate a rails 3 application with jasper after this wiki:

http://wiki.rubyonrails.org/rails/pages/HowtoIntegrateJasperReports

But it seems that a lot of information is not updated, so it is very difficult to make it work independently. I also read the topic on the ruby-forum : http://www.ruby-forum.com/topic/139453 with some details explained, but still could not get it to work.

My first problem is with the render_to_string method: When the controller method starts, I get the message "Template missing":

this is the method:

def report @customers = Customer.all send_doc(render_to_string(:template => report_customers_path, :layout => false), '/pdfs', 'report.jasper', "customers", 'pdf') end 

Although this seems simple, I do not understand why this is happening. Doesn't support render_to_string with layout => false to get a string result of this action? I also tried : action instead of : template , but it does the same.

If anyone with some knowledge of this integration can help ... Thanks in advance, Andre

+8
ruby ruby-on-rails ruby-on-rails-3 jasper-reports
source share
4 answers

We actually use jasperreports to create reports and have recently upgraded to Rails 3.0. To create xml, we use xml.erb templates. Jasper reports run on a separate server of sea fish. Here's a general idea:

 url = URI.parse(my_url_string) dataxml = render_to_string(:template => my_template_name).gsub(/\n/, '') params = {'type' => 'pdf', 'compiledTemplateURI' => my_jasper_file, 'data' => dataxml } request = Net::HTTP::POST.new(url.request_uri) request.set_form_data(params) obj = Net::HTTP.new(url.host, url.port) obj.read_timeout = my_timeout_setting response = obj.start { |http| http.request(request) } case response when Net::HTTPOK send_data(response.body, :filename => my_chosen_filename, :type => "application/pdf", :disposition => "inline") else raise "failed to generate report" end 
+1
source share

I don't know anything about jasper, but it looks like you want to do two things: render the PDF template, and then send the original output back with the PDF file type:

 pdf_contents = render_to_string(:template => 'users/report') send_data(pdf_contents, :file_name => 'report.pdf', :type => 'application/pdf') 

You pass the external URL as the path to the template, but this is probably wrong if you get errors regarding the path to the template. First correct the template path.

0
source share

Try changing the render_to_string() code to the following:

 @customers.to_xml 
0
source share

Use savon to interact with jaserserver in rails3. Here is an example:

 require 'logger' require 'savon' logger = Logger.new(STDOUT) logger.info "Test jasper via Savon-SOAP" @client = Savon::Client.new { wsdl.document = "http://localhost:8080/jasperserver/services/repository?wsdl" http.auth.basic "jasperadmin", "jasperadmin" } logger.info "runReport method" begin result = @client.request :run_report do soap.body = "<requestXmlString> <![CDATA[ <request operationName='runReport' > <argument name='RUN_OUTPUT_FORMAT'>PDF</argument> <resourceDescriptor name='' wsType='' uriString='/reports/samples/AllAccounts' isNew='false'> <label></label> </resourceDescriptor> </request> ]]> </requestXmlString>" end send_data result.http.raw_body, :type => 'application/pdf', :filename => 'report.pdf', :disposition => 'attachment' rescue Exception => e logger.error "SOAP Error: #{e}" end 
0
source share

All Articles