Experimental JasperReports/Rails integration using Rjb (Ruby Java Bridge)
For rspec integration, see: jasper-rails-rspec.
You need a Java Virtual Machine installed and set up in order to use this gem.
gem install jasper-rails
jasper-rails to your Gemfile:
Note: If you're running your application on OS X, this is usually all you have to do. On Linux, you might have to set the JAVA_HOME. On Windows, good luck!
For any issues related to the java/ruby integration, please check out: http://rjb.rubyforge.org/. You will find here plenty tips that might help you to solve your problem.
1) Tell your controller that it "responds to" :pdf and it "responds with" some list:
Note: This list will become your datasource inside the report.
respond_to :html, :xml, :pdf def index @people = Person.all respond_with @people end
2) Create your jasper report source file using iReport or any compatible jasper tool.
3) Set the "Query Text" and "The language for the dataset query" properties of your report.
Note: If you're using iReport, you can find those properties in the "Properties panel". Don't forget to select the report root node in your "Report inspector".
Example: If you have a list of people, you should have something like:
- "Query Text" = /people/person
- "The language for the dataset query" = xpath
4) Design your report (add fields, groups, images, etc.)
5) Save the report source file in your views folder (just like any other html view file):
def index @people = Person.all # This variable will be available in your report! @user = "John Doe" respond_with @people end
All you have to do now is to create, in iReport, a parameter called "user" (yes, without the "@") and drop it in your report!
Limitation: By now, all parameters are converted to java String. We intend to change this in the near future.
Check out: jasper-rails-rspec.
For a running example, just clone: jasper-rails-demo.
Is this gem still experimental?
YES. We have just migrated this code from a internal project at Grupo Fortes. We already use this gem in a couple of projects and we are very happy with it. However, pay attention that all the features it supports right now were based in those project's especific needs. Therefore you might find a lot of JasperResports' features that are not yet supported. So, use it at your own risk!
- Better error treatment
- More RSpec matchers
Copyright (C) 2012 Marlus Saraiva, Rodrigo Maia
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.