Using :transforms with :include (acts_as_reportable)

10 views
Skip to first unread message

Paul Lynch

unread,
Jun 8, 2010, 3:23:09 PM6/8/10
to Ruby Reports
I'm new to ruport, and I think this question might only apply to
acts_as_reportable. In the report_table method, is it possible to
use :transforms to do a transform on a column being included
via :include?

I would like to do:
SomeTable.report_table(:all, :include=>{:other_table_records=>{:transform=>lambda{|
other_table_rec| { other_table_rec.col = 'new value' }}})

But that doesn't seem to work. It complains that method 'col' is not
defined on Ruport::Data::Record, as though the transform were being
run before the include....

Thanks,
--Paul

Andrew France

unread,
Jun 8, 2010, 9:08:19 PM6/8/10
to ruby-r...@googlegroups.com
Hi Paul,

I've never used the :transform option. I think the proper way to access
a column would be:
other_table_rec['col']

I think :transform will only work at the same level of include after all
the data has been collected. Not sure it makes sense on individual
associations. So it should be more like:

So: SomeTable.report_table(:all, :include => {other: => ...}, :transform
=> lambda {|tb| tb['other.col_a'] = ...})

Alternatively you can simply generate the table and use the table
methods to manipulate the data.

Hope that helps,
Andrew

Paul Lynch

unread,
Jun 10, 2010, 10:56:33 AM6/10/10
to Ruby Reports
Thanks the reply-- I had not known about the ability change values in
the table, but I see now that that acts just like an array. It would
not have been an ideal solution in my case, because the transformation
I wanted to do on the included record was calling a method on it and
then referencing a value from the method's returned hash. (I'm not
sure that would have been possible anyway.) I ended up opening up the
class before I build the table and adding a method that does all that,
so that I can just use the :method parameter to report_table.
Reply all
Reply to author
Forward
0 new messages