removing the www before a domain with Rails3?

In Rails2 I used a middleware to redirect www.mydomain.tld to
Something like this:
It is in Libs, with filename "no_www.rb".
I tryed to add as the first line of environment.rb as suggested in

When it failed l put it in application,rb, the first line after class
Application < Rails::Application in application.rb is:
config.middleware.use "NoWWW"
But when I try to run the app I get: C:/Ruby/lib/ruby/gems/1.9.1/gems/
`block in constantize': uninitialized constant NoWWW (NameError)

Any idea how to use it? Unfortunately I can't use mod_rewrite, since I
plan to put the app. on Heroku.

I have found the solution.
The config.middleware.use should be put into application.rb, and the /
lib is no longer loaded automatically so you need to load it, like

  class Application < Rails::Application
    config.autoload_paths += %W(#{Rails.root}/lib)
    config.middleware.use "NoWWW"

Hope this helps someone.