Jump to content

Ruby on Rails client for JasperServer


mzukowski

Recommended Posts

Variations of this have been posted here, however the old code had some bugs... this version works very well for us:

 

http://pastebin.com/f4914d4db

 

 

Here's a usage example (as a Rails controller action method):

 

Code:

def jasper_for_rails_example

format = params[:format].downcase # e.g. 'PDF'
mimetype = Mime::Type.lookup_by_extension(format)

jasper = JasperClient.new(:username => 'foo', :«»password => 'bar')
data = jasper.jasper.run_report('/foo/bar-report',
format,
'start_date' => Time.parse(params['start_date']),
'end_date' => Time.parse(params['end_date']),
'some_other_param' => params['some_other_param']
)

send_data(data, :type => mimetype)
end
Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Thank you so much for your code. Your code is cleaner than the one I have in my jasper_runner plugin. Do you mind if use it in my plugin?

 

On the other hand, the sample client you posted has some typos. I believe it should be like this to work:

Code:

def jasper_for_rails_example



format = params[:format] # e.g. 'PDF': format must remain uppercase for jasper to recognize it

mimetype = Mime::Type.lookup_by_extension(format.downcase)



jasper = JasperSoapClient.new(:username => 'foo', :«»password => 'bar')

data = jasper.run_report('/foo/bar-report',

format,

'start_date' => Time.parse(params['start_date']),

'end_date' => Time.parse(params['end_date']),

'some_other_param' => params['some_other_param']

)



send_data(data, :type => mimetype)

end

 

As a side note, I tested your code with a rails app running on Jruby and it works as long as I fix the httpclient.rb file (from the soap4r gem) to set SSLEnabled = false.

 

Best regards,

juantar

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...