fortesinformatica / jasper-rails

JasperReports on Rails
MIT License
62 stars 36 forks source link

Calling jasper in controller with format - render -> template is missing #17

Closed ionosphere closed 11 years ago

ionosphere commented 11 years ago

I have a little mistake concerning the call of Jasper in a controller. I need a complete xml datasource with association.

see https://github.com/ekylibre/ekylibre/issues/90

Do you know why ? because I am not a ruby/rails jedy.

msaraiva commented 11 years ago

As far as I can remember, the render method, by default, first check if the resource has a method for rendering the required type (in your case the @animal variable would need a "to_pdf" method). Jasper-rails does not add this method to the resource like rails does with the "to_xml" and "to_json". Rails does this at a model level, jasper-rails work together with "respond_with" at a controller/responder level. So if you want to have different render options for different formats you can still use the "respond_to" method but for the pdf format you will need to stick with respond_with. In your case, try:

format.pdf { respond_with @animal }

instead of:

format.pdf { render pdf: @animal }

it should work without any issues.

ionosphere commented 11 years ago

OK, thanks, it work with render_with @animal but i haven't access to my xml render with :include association. In this case, we have only the standard xml view with no association which need to make a lot of subqueries in Ireport. If we can have the xml render with:include option , we can use the power of rail and it could be much easier to make report in Ireport. What's your opinion ?

msaraiva commented 11 years ago

You can use the :include option with "respond_with" just like you do with the "render" method. I don't know exactly what you mean by "a lot of subqueries". If you're talking about the activerecord's n+1 problem, take a look at http://guides.rubyonrails.org/active_record_querying.html and search for the "includes" method. It should solve your problem.

ionosphere commented 11 years ago

Le 04/01/2013 10:10, Marlus a écrit :

You can use the :include option with "respond_with" just like you do with the "render" method. I don't know exactly what you mean by "a lot of subqueries". If you're talking about the activerecord's n+1 problem, take a look at http://guides.rubyonrails.org/active_record_querying.html and search for the "includes" method. It should solve your problem.

— Reply to this email directly or view it on GitHub https://github.com/fortesinformatica/jasper-rails/issues/17#issuecomment-11876003.

Thanks, it works perfectly with this code

def index @animal = Animal.all respond_with @animal, :include => [:race , :father, :mother] end