Currently I have...
-----------------
class MyControler < ActionController::Base
...
def example
activities = Activity.report_table(:all)
@activities = Grouping.new(activities, :by=>'activity_type')
end
...
end
-----------------
example.report
draw_table(activities)
-----------------
This throws an exception since the Grouping does not have the
necessary column_names collection.
Thanks,
AndyV
I tried both recommendations above. I got the first one (send_data)
to work without any problem. The only thing that I did not like was
that the pdf came down as a file download rather than displayed as a
PDF in the browser.
The second approach did not work. I'd tried something similar earlier
in the evening but tried again this morning and still got the 'missing
column_names' exception. I've hacked around it and come up with this
(very ugly) code to make it work. I'm sure there is a better way and
open to any suggestions.
example.report
-------------------------------------------------------------------------------------------------------------------------
| options.paper_size = "letter"
|
| add_text "Alphabetical listing of
Activities", :justification=>:center, :font_size=>14
|
| pad(4) do
| add_text "by Andy Vanasse", :justification=>:center, :font_size=>10
| end
|
| @activities.each do |group|
| group.each do |row|
| if row.is_a?(String)
| pad(10) { add_text row.pluralize, :font_size=>12 }
| else
| draw_table(row, :width=>400, :font_size=>10)
| end
| end
|
| end
-------------------------------------------------------------------------------------------------------------------------
For reference, the example action looks like this:
def example
activities = Activity.report_table(:all, :order=>'activity_type,
name', :except=>:id)
@activities = Grouping(activities, :by=>'activity_type')
logger.debug @activities.to_s
end
Best regards,
AndyV
On May 2, 11:09 pm, "Michael Milner" <mikem...@gmail.com> wrote:
it looks like Mike may have given you the wrong signature for Grouping#each
>> a = Table(%w[a b]) << %w[apple banana]
>> a << %w[cat dog]
>> a << %w[apple cat]
>> grouping = Grouping(a,:by => "a")
You tried this:
>> grouping.each { |g| p g.class }
Array
Array
What you probably want is this:
>> grouping.each { |name,group| p group.class }
Ruport::Data::Group
Ruport::Data::Group
It yields name,group, not just group.
I'll make the change in your code below.
> example.report
> -------------------------------------------------------------------------------------------------------------------------
> | options.paper_size = "letter"
> |
> | add_text "Alphabetical listing of
> Activities", :justification=>:center, :font_size=>14
> |
> | pad(4) do
> | add_text "by Andy Vanasse", :justification=>:center, :font_size=>10
> | end
> |
+ | @activities.each do |name,group|
+ # add :title => name if you want the group's name added to
the top of the table
> | draw_table(group, :width=>400, :font_size=>10)
> | end
> |
> | end
> -------------------------------------------------------------------------------------------------------------------------
Let me know if that does the trick.
> it looks like Mike may have given you the wrong signature for Grouping#each
For what it's worth, I may have IMed him that bad signature, so you
can blame me :)
On May 3, 10:09 am, "Gregory Brown" <gregory.t.br...@gmail.com> wrote:
The API docs are also silent on this, but I'll fix that today.
Warm Regards,
-gregory
On May 3, 10:10 am, "Gregory Brown" <gregory.t.br...@gmail.com> wrote:
http://stonecode.svnrepository.com/ruport/trac.cgi/changeset/885
Minimal, but at least the yield args will show up properly in the docs now.
> The only thing that I did not like was
> that the pdf came down as a file download rather than displayed as a
> PDF in the browser.
try something like this:
send_data @activities.to_pdf, :type => "application/pdf", :disposition
=> 'inline'
Regards,
Timo