respond_to .... format.pdf - undefined method `to_sym' for PDF:Module

458 views
Skip to first unread message

Tonypm

unread,
Aug 11, 2010, 9:35:48 AM8/11/10
to Prawn
Hi,

I wonder if anyone can help me with this:

I am not sure how it is occuring, and it may be a rails issue rather
than prawn, but I thought I would start here to see if anyone has any
ideas.
On my production server I am getting an

undefined method 'to_sym' error in my actions that use

respond_to |format| do
format.pdf do

The error occurs in more than one controller at the format.pdf block,
regardless if the pdf format is being requested. If I remove the
format.pdf block and just test the format with an if statement then
all is ok. I am using nginx on the server and the error has occurred
after vendoring prawn 10.2 (stable). The code worked fine previously
with the earlier prawn gems - and works on another server running a
different app.

Unfortunately, I cannot reproduce this on my development machine even
using nginx with the same config files and identical prawn version
etc.

I am suspecting a config issue on my server, but I am stuck to know
how to run this to ground.

The pdf is rendered into a variable prior to the respond_to block, so
I cannot think why the processing of the request should be involving
the Prawn module.

If anyone has any ideas to offer I would be most grateful

The log looks like this: (line 224 is the respond_to line and 237 is
the format.pdf line)

NoMethodError (undefined method `to_sym' for PDF:Module):
/usr/lib/ruby/1.8/delegate.rb:136:in `any?'
app/controllers/batches_controller.rb:237:in `invoices'
app/controllers/batches_controller.rb:224:in `invoices'
haml (3.0.4) rails/./lib/sass/plugin/rack.rb:41:in `call'
passenger (2.2.4) lib/phusion_passenger/rack/request_handler.rb:
91:in `process_request'
passenger (2.2.4) lib/phusion_passenger/abstract_request_handler.rb:
206:in `main_loop'
passenger (2.2.4) lib/phusion_passenger/railz/application_spawner.rb:
376:in `start_request_handler'
passenger (2.2.4) lib/phusion_passenger/railz/application_spawner.rb:
334:in `handle_spawn_application'
passenger (2.2.4) lib/phusion_passenger/utils.rb:182:in `safe_fork'
passenger (2.2.4) lib/phusion_passenger/railz/application_spawner.rb:
332:in `handle_spawn_application'
passenger (2.2.4) lib/phusion_passenger/abstract_server.rb:351:in
`__send__'
passenger (2.2.4) lib/phusion_passenger/abstract_server.rb:351:in
`main_loop'
passenger (2.2.4) lib/phusion_passenger/abstract_server.rb:195:in
`start_synchronously'
passenger (2.2.4) lib/phusion_passenger/abstract_server.rb:162:in
`start'
passenger (2.2.4) lib/phusion_passenger/railz/application_spawner.rb:
213:in `start'
passenger (2.2.4) lib/phusion_passenger/spawn_manager.rb:261:in
`spawn_rails_application'
passenger (2.2.4) lib/phusion_passenger/
abstract_server_collection.rb:126:in `lookup_or_add'
passenger (2.2.4) lib/phusion_passenger/spawn_manager.rb:255:in
`spawn_rails_application'
passenger (2.2.4) lib/phusion_passenger/
abstract_server_collection.rb:80:in `synchronize'
passenger (2.2.4) lib/phusion_passenger/
abstract_server_collection.rb:79:in `synchronize'
passenger (2.2.4) lib/phusion_passenger/spawn_manager.rb:254:in
`spawn_rails_application'
passenger (2.2.4) lib/phusion_passenger/spawn_manager.rb:153:in
`spawn_application'
passenger (2.2.4) lib/phusion_passenger/spawn_manager.rb:286:in
`handle_spawn_application'
passenger (2.2.4) lib/phusion_passenger/abstract_server.rb:351:in
`__send__'
passenger (2.2.4) lib/phusion_passenger/abstract_server.rb:351:in
`main_loop'
passenger (2.2.4) lib/phusion_passenger/abstract_server.rb:195:in
`start_synchronously'

Tonypm

Brad Ediger

unread,
Aug 11, 2010, 9:46:16 AM8/11/10
to prawn...@googlegroups.com
On Wed, Aug 11, 2010 at 8:35 AM, Tonypm <tonyp...@hotmail.com> wrote:
> Hi,
>
> I wonder if anyone can help me with this:
>
> I am not sure how it is occuring, and it may be a rails issue rather
> than prawn, but I thought I would start here to see if anyone has any
> ideas.
> On my production server I am getting an
>
> undefined method 'to_sym' error in my actions that use
>
> respond_to |format| do
>   format.pdf do
>
> The error occurs in more than one controller at the format.pdf block,
> regardless if the pdf format is being requested.

This is really more of a question for the Rails list. But one thing I
usually forget when rendering PDF actions is to add the
application/pdf MIME type in an initializer:

Mime::Type.register "application/pdf", :pdf

-be

James Healy

unread,
Aug 11, 2010, 10:06:00 AM8/11/10
to prawn...@googlegroups.com
Brad Ediger wrote:
> This is really more of a question for the Rails list. But one thing I
> usually forget when rendering PDF actions is to add the
> application/pdf MIME type in an initializer:
>
> Mime::Type.register "application/pdf", :pdf

Recent versions of prawn depend on the PDF::Reader gem, which creates a
namespace clash between the PDF module from that and the PDF class
created when you register a mime type in rails.

I hadn't considered this side effect before, but I have run into the
same issue with the CSV library in the 1.9 standard lib.

In the CSV case I just serve CSV files with an excel mime type, but I'm
not sure what the best idea is in this case.

-- James Healy <ji...@deefa.com> Thu, 12 Aug 2010 00:05:47 +1000

Tonypm

unread,
Aug 11, 2010, 10:57:53 AM8/11/10
to Prawn

Thank you so much guys.

Adding the Mime::Type to initializers solved the problem.

I confess to having completely overlooked it.
Strange that it worked till I updated prawn.

Anyway your quick responses - much appreciated. All is now well
again.

Tonypm

Wellington Torrejais Hotsoft

unread,
Nov 10, 2016, 1:20:59 PM11/10/16
to Prawn
  Mime::Type.register "application/pdf", :pdf worked for me too! Thanks!
Reply all
Reply to author
Forward
0 new messages