# Problem registering Mime type

**URL:** <https://www.ruby-forum.com/t/problem-registering-mime-type/160113>\
**Category:** Rails\
**Created:** [February 11, 2009, 10:06pm UTC](https://www.ruby-forum.com/t/problem-registering-mime-type/160113 "2009-02-11T22:06:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zufar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5f8ce5/32.png) [@zufar](https://www.ruby-forum.com/u/zufar)\
**Post date:** [February 11, 2009, 10:06pm UTC](https://www.ruby-forum.com/t/problem-registering-mime-type/160113/1 "2009-02-11T22:06:31Z")

</div>

I am facing problem trying to register pdf Mime type. I am doing this  
in environment.rb:

RAILS\_GEM\_VERSION = ‘2.1.0’ unless defined? RAILS\_GEM\_VERSION

require File.join(File.dirname( **FILE** ), ‘boot’)

#Pagination  
require ‘rubygems’  
require ‘prawn’

Mime::Type.register “application/pdf”, :pdf

STORE\_LOCATION\_METHOD = :store\_location

Rails::Initializer.run do |config|  
end

require ‘will\_paginate’

#Dealing with numbers  
require ‘bigdecimal’  
require ‘bigdecimal/math’

While doing so, I tried restarting Mongrel. But, the server is failing  
to start and throwing the following error:  
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active\_support/dependencies.rb:278:in  
`load\_missing\_constant’: uninitialized constant Mime (NameError)

Please do help!

---

<div class="post-metadata">

**Author:** ![zufar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5f8ce5/32.png) [@zufar](https://www.ruby-forum.com/u/zufar)\
**Post date:** [February 11, 2009, 10:35pm UTC](https://www.ruby-forum.com/t/problem-registering-mime-type/160113/2 "2009-02-11T22:35:20Z")

</div>

Solved the problem!

This is weird though, I had to put “Mime::Type.register  
“application/pdf”, :pdf”  
after the initializer code.

The following thing worked for me, environment.rb:

RAILS\_GEM\_VERSION = ‘2.1.0’ unless defined? RAILS\_GEM\_VERSION

require File.join(File.dirname( **FILE** ), ‘boot’)

#Pagination  
require ‘rubygems’  
require ‘google\_chart’  
require ‘prawn’

Rails::Initializer.run do |config|  
end

require ‘will\_paginate’  
Mime::Type.register “application/pdf”, :pdf

#Dealing with numbers  
require ‘bigdecimal’  
require ‘bigdecimal/math’  
BigDecimal.mode(BigDecimal::ROUND\_MODE,BigDecimal::ROUND\_HALF\_EVEN)  
BigDecimal.limit(20)

Explanation? anybody?

Aslam S. wrote:

> I am facing problem trying to register pdf Mime type. I am doing this  
> in environment.rb:
> 
> RAILS\_GEM\_VERSION = ‘2.1.0’ unless defined? RAILS\_GEM\_VERSION
> 
> require File.join(File.dirname( **FILE** ), ‘boot’)
> 
> #Pagination  
> require ‘rubygems’  
> require ‘prawn’
> 
> Mime::Type.register “application/pdf”, :pdf
> 
> STORE\_LOCATION\_METHOD = :store\_location
> 
> Rails::Initializer.run do |config|  
> end
> 
> require ‘will\_paginate’
> 
> #Dealing with numbers  
> require ‘bigdecimal’  
> require ‘bigdecimal/math’
> 
> While doing so, I tried restarting Mongrel. But, the server is failing  
> to start and throwing the following error:  
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active\_support/dependencies.rb:278:in  
> `load\_missing\_constant’: uninitialized constant Mime (NameError)
> 
> Please do help!

---

<div class="post-metadata">

**Author:** ![zufar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5f8ce5/32.png) [@zufar](https://www.ruby-forum.com/u/zufar)\
**Post date:** [February 25, 2009, 2:30am UTC](https://www.ruby-forum.com/t/problem-registering-mime-type/160113/3 "2009-02-25T02:30:04Z")

</div>

Asylam, I have been facing the same problem and came across your post  
and solution. Thank you for posting your solution.

I was suprised that the Ruby runtime even executes code outside of the  
Initialize method on the environment.rb. I thought that was the only  
event handler it invoked within environment.rb. How did you know to  
do this? I would appreciate any insight you may have that would make  
sense out of this.
