acts_as_reportable and pdf

22 views
Skip to first unread message

ed

unread,
Feb 2, 2009, 6:58:27 PM2/2/09
to Ruby Reports
I've got ruport 1.6.1 and aar 1.1.1 installed. The project I'm trying
to add ruport into is using rails 2.1.0

When using the config.gem feature, I get an error when trying to
specify the acts_as_reportable gem. ruport does just fine, however.

config.gem "acts_as_reportable", :version=>'1.1.1'

I get a "no such file to load -- acts_as_reportable" plus a nice long
stack trace. Anyone else see this too? This isn't a big deal.

Question:
I'm trying to use the aar to throw up some quick and dirty reports and
I am able to do so with html and csv formats. However my attempt at
doing it with pdf fails.

table = Member.report_table(:all,
:only=>["user.first_name", "user.last_name",
:phone1, :phone1_tag, :phone2, :phone2_tag],
:include => {:user=>{:only=>[:first_name, :last_name]}},
:order=>'users.last_name'
)

What works:
@text = table.as(:html).sub(/\<table/, '<table class="data"')
@csv = table.as(:csv)

What doesn't:
@pdf = table.render_pdf
@pdf = table.as(:pdf)

Does aar not support pdf rendering or (more likely) am I not using it
correctly to get a pdf?

As an aside, what do people do when trying to render html, but need to
customize the tags with ids or tags?

BTW, thanks for Ruport and aar, great work.

Thanks,
Ed

Andrew France

unread,
Feb 3, 2009, 2:48:53 PM2/3/09
to Ruby Reports

On Feb 2, 11:58 pm, ed <eddyh...@gmail.com> wrote:
> When using the config.gem feature, I get an error when trying to
> specify the acts_as_reportable gem.  ruport does just fine, however.

I don't tend to use Rails' gem handling so haven't noticed this, if
you could please post the first 3 or so lines of the trace, or use a
pastie service for the whole thing, that would be appreciated, thanks!
Would also need to know 'gem --version'.

> I'm trying to use the aar to throw up some quick and dirty reports and
> I am able to do so with html and csv formats.  However my attempt at
> doing it with pdf fails.

> What works:
>       @text = table.as(:html).sub(/\<table/, '<table class="data"')
>       @csv = table.as(:csv)
>
> What doesn't:
>       @pdf = table.render_pdf
>       @pdf = table.as(:pdf)
>
> Does aar not support pdf rendering or (more likely) am I not using it
> correctly to get a pdf?

It should work as you expect, what happens? Hopefully an exception and
not just an empty string! :P

> As an aside, what do people do when trying to render html, but need to
> customize the tags with ids or tags?

Last time I did this I wrote custom methods in the formatter that
iterated over the data and concatenated HTML strings, this may be
wrong and hopefully someone will suggest a better way.

Best regards,
Andrew

eddy

unread,
Feb 5, 2009, 3:14:12 AM2/5/09
to ruby-r...@googlegroups.com
Hi Andrew,

Sorry for the delay in response, I was away from internet access for a bit.


Andrew France wrote:
> I don't tend to use Rails' gem handling so haven't noticed this, if
> you could please post the first 3 or so lines of the trace, or use a
> pastie service for the whole thing, that would be appreciated, thanks!
> Would also need to know 'gem --version'.
>
>

** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...


no such file to load -- acts_as_reportable

/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in
`require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in
`new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in
`require'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/rails/gem_dependency.rb:57:in
`load'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/symbol.rb:11:in
`__send__'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/symbol.rb:11:in
`to_proc'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/initializer.rb:246:in `each'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/initializer.rb:246:in
`load_gems'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/initializer.rb:137:in `process'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/initializer.rb:93:in `send'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/initializer.rb:93:in `run'
/home/eddyk/ruby/lard7/config/environment.rb:13

[many more lines of stack trace]

./script/server:3
These gems that this application depends on are missing:
- acts_as_reportable
Run "rake gems:install" to install them.
** Rails loaded.
** Loading any Rails specific GemPlugins

acts_as_reportable is installed on the system, because when I comment
out the config.gem line, I can use it.


>> What works:
>> @text = table.as(:html).sub(/\<table/, '<table class="data"')
>> @csv = table.as(:csv)
>>
>> What doesn't:
>> @pdf = table.render_pdf
>> @pdf = table.as(:pdf)
>>
>> Does aar not support pdf rendering or (more likely) am I not using it
>> correctly to get a pdf?
>>
>
> It should work as you expect, what happens? Hopefully an exception and
> not just an empty string! :P
>

Curious. I tried it again to get a cut and paste of the error message,
and somehow this time it worked (?)!

Cheers,
Ed

Matt Simpson

unread,
Mar 27, 2009, 2:42:27 PM3/27/09
to Ruby Reports
I'm getting this too, what did you do to resolve it? if anything.

Steve Messamore

unread,
Mar 27, 2009, 9:49:11 PM3/27/09
to ruby-r...@googlegroups.com
Hi Matt,
Put this in your environment file and you should be good to go.

Steve Messamore

config.after_initialize do
gem "ruport", "=1.6.1"
require "pdf/writer"
require "ruport"
require "ruport/util"
require "acts_as_versioned"
require "ruport/extensions"
require "#{RAILS_ROOT}/app/views/templates/templates"
#Dir[File.join(RAILS_ROOT, "lib", "extensions", "*.rb")].each {|f|
require f}
end

Andrew France

unread,
Mar 30, 2009, 1:17:30 PM3/30/09
to ruby-r...@googlegroups.com
Hi Matt and Steve,

Sorry for the delay, I was away at Scotland on Rails. :)

> ** Starting Mongrel listening at 0.0.0.0:3000
> ** Starting Rails with development environment...
> no such file to load -- acts_as_reportable
> /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
> `gem_original_require'
> /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'

Been looking into this issue and I think it's probably our mistake. For
starters, the Ruport gem should automatically load acts_as_reportable if
it detects it's in a Rails app, so simply having: config.gem 'ruport'
should give you the functionality, I suspect this is not obvious from
the documentation or may not work anymore!

Secondly you would expect require 'acts_as_reportable' to work anyway
right? Unfortunately the correct command is:
require 'ruport/acts_as_reportable'
Which is a bit inconsistent with how other gems work I think but I
suppose makes sense as it depends on Ruport.

I don't have the latest Rubygems (and don't want to break my Ubuntu
package management) so would be grateful if someone could try the above
with Rails' config.gem methods and let me know if I'm right. Then I will
have a look at the best way to fix it!

Best regards,
Andrew

Gregory Brown

unread,
Mar 30, 2009, 7:56:48 PM3/30/09
to ruby-r...@googlegroups.com
On Mon, Mar 30, 2009 at 1:17 PM, Andrew France <andrew...@avito.co.uk> wrote:

> Been looking into this issue and I think it's probably our mistake. For
> starters, the Ruport gem should automatically load acts_as_reportable if
> it detects it's in a Rails app, so simply having: config.gem 'ruport'
> should give you the functionality, I suspect this is not obvious from
> the documentation or may not work anymore!

This check is based on whether ActiveRecord has been loaded. So if
config.gem loads the gems before the Rails Env is initialized, then
AAR will not be loaded by require "ruport"

> Secondly you would expect require 'acts_as_reportable' to work anyway
> right? Unfortunately the correct command is:
> require 'ruport/acts_as_reportable'
> Which is a bit inconsistent with how other gems work I think but I
> suppose makes sense as it depends on Ruport.

Technically his is for (ancient) backwards compatibility. AAR used to
be a part of Ruport.

But it's also to avoid name collisions. If all 'official' Ruport
extensions are under 'ruport/....' we're less likely to clash with
other requires.
Admittedly, this is more important for generic things like
ruport/util, so if this is something people would really like to see
change, adding a stub that makes require "acts_as_reportable" would be
fine by me.

Anyway Andrew, It's your call on this stuff, this post is just for background.

-greg

Reply all
Reply to author
Forward
0 new messages