Generating PDFs for Groupings

0 views
Skip to first unread message

Peter

unread,
Nov 2, 2008, 7:57:21 PM11/2/08
to Ruby Reports
I have a question regarding the Tattle Project Example from the online
book Ruport Ruby Reports. First of all, I have to complement the
authors on a great book. Having worked with Ruport for only a week
now, I find the book to be a very useful reference. Thank you!

The Tattle example is a perfect introduction to Ruport and I was able
to generate similar PDF reports for grouped tables. The problem I
have is getting that exact problem working within a Ruport::Controller
using the constructs that you recommend later in your book.
Specifically,
How do I generate a PDF file for a *grouping* within a
Ruport::Controller file, or maybe even the class PDF <
Ruport::Formatter::PDF within that file?
What is the construct for calling that report from within my general
controller? I would like to be able to control the disposition and
filename like the example.

Here is the code snippet from the book. I assume the 'send_data'
segment would remain in the Rails controller, but how does the rest of
it change in the Ruport::Controller?

def generate_report
table = Report.report_table(:all,
:only => %w[host_os rubygems_version user_key],
:conditions => "user_key is not null and user_key <> ''",
:group => "host_os, rubygems_version, user_key")

grouping = Grouping(table, :by => "host_os")
...
send_data g.to_pdf,
:type => "application/pdf",
:disposition => "inline",
:filename => "report.pdf"
end

I did find a somewhat related discussion thread from this group
"send_data PDF and CSV not working for Grouping" , but it does not
completely address my questions.

I'm relatively new to Ruby, so my questions are probably very simple
for seasoned programmers. I apologize if this is already show this in
the book and I missed it. If it's not in the book, I think it would
be great to have a small follow-up section in the book that describes
how to properly implement the Tattle example.

Peter

unread,
Nov 6, 2008, 9:31:27 AM11/6/08
to Ruby Reports
After more research and reading many posts on this board (great
resource!), I figured out what I needed to do to create a PDF for a
grouping. Pretty simple.

class PDF < Ruport::Formatter::PDF
renders :pdf, :for => UserSummaryReport
include StandardPDFReport

def build_list
grouping = Grouping(data, :by => options.group_name)
grouping.sort_grouping_by! { |g| g.name }
grouping.each do |name,group|
draw_table group
pdf_writer.start_new_page
end
end
end

Gregory Brown

unread,
Nov 6, 2008, 9:39:15 AM11/6/08
to ruby-r...@googlegroups.com
On Thu, Nov 6, 2008 at 9:31 AM, Peter <pmm....@gmail.com> wrote:
>
> After more research and reading many posts on this board (great
> resource!), I figured out what I needed to do to create a PDF for a
> grouping. Pretty simple.

Cool. Sorry that I didn't get back to you on this Peter, things are
chaotic around RubyConf. :)

-greg

--
Technical Blaag at: http://blog.majesticseacreature.com | Non-tech
stuff at: http://metametta.blogspot.com

Reply all
Reply to author
Forward
0 new messages