Forum: Ruby on Rails Problem registering Mime type

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4b57319c67f743ca71321465b73d4104?d=identicon&s=25 Aslam Syed (zufar)
on 2009-02-11 22:06
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!
4b57319c67f743ca71321465b73d4104?d=identicon&s=25 Aslam Syed (zufar)
on 2009-02-11 22:35
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 Syed 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!
34854d418156dfbf8a0103977bbab2e4?d=identicon&s=25 RubyNewbie (Guest)
on 2009-02-25 02:30
(Received via mailing list)
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.
This topic is locked and can not be replied to.