warning: already initialized constant PDF
Asked Answered
C

2

32

Right now I am working on rails 3.0.0. If I run my project in terminal, I get this warning. Please help me.

/usr/share/ruby-rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.0/lib/action_dispatch/http/mime_type.rb:98: warning: already initialized constant PDF

Cheddar answered 8/6, 2012 at 7:3 Comment(3)
You might look in environment.rb to see if you have a PDF mime-type listed twiceCharmian
Are you using a PDF library such as Prawn?Preceptor
are you using Wicked PDF? github.com/mileszs/wicked_pdf/pull/82Primatology
O
62

You might have this in your config/initializers/mime_types.rb file.

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

It looks like newer versions of rails already registers it.

Oversweet answered 20/8, 2012 at 5:35 Comment(5)
are you sure that rails registers it by default now?Battement
No i'm not sure. It could also be caused by other gems registering it as well.Oversweet
Yes, sure, it was added on 2011-06-27 in this commit github.com/rails/rails/commit/…Ransdell
I had a similar problem. Even though I wasn't registering the :pdf mime type myself, one of the gems I was using was too old and still doing that. When I upgraded the gem to a later version, the error disappeared. If you can't find the source code, likely one of your gems is the culprit.Hora
@AminAriana I had similar case but decided to solve it with re-registering the mime-type. For that I did Mime::Type.unregister(:csv) at first in mime-types initializer and after that registered csv-type again with desired new attributes.Imprecate
B
30

Try using lookup_by_extenstion before defining it.

I have this on my config/initializers/mime_types.rb file.

Mime::Type.register "application/pdf", :pdf unless Mime::Type.lookup_by_extension(:pdf)
Bart answered 16/7, 2014 at 0:26 Comment(4)
May not be necessary, but it's safer. Thanks!Joletta
I was having the same error in Rails 3.2.14 using the Prawn gem. Changing Mime::Type.register "application/pdf", :pdf to Mime::Type.register "application/pdf", :pdf unless Mime::Type.lookup_by_extension(:pdf) did the trick! Thanks!Cambric
Simply removing the Mime::Type.register 'application/pdf', :pdf gave me errors, but Mime::Type.register "application/pdf", :pdf unless Mime::Type.lookup_by_extension(:pdf) did the trickDispersive
You might want to extend that a bit to make sure the previous registration is actually identical to the one you are making: Mime::Type.register "application/pdf", :pdf unless Mime::Type.lookup_by_extension(:pdf) == "application/pdf"Plasticity

© 2022 - 2024 — McMap. All rights reserved.