3

I have a class sitting in /lib folder. It's in a file called mailing.rb

And I would like to use this class in codes from app/controller.

How do i do this?

Jason Kim
  • 18,102
  • 13
  • 66
  • 105
  • 1
    There is an answer to a similar question [Rails /lib modules and](http://stackoverflow.com/questions/1073076/rails-lib-modules-and) from @YehudaKatz. – mliebelt Sep 29 '11 at 15:00

2 Answers2

10

Rails 3 no longer automatically loads the files from lib.

In your application.rb file, you can add lib to your autoload_paths:

config.autoload_paths += Dir["#{Rails.root}/lib"]

This way, your mailer.rb and all other files in lib will be available to the rest of your application.

keithepley
  • 4,760
  • 3
  • 23
  • 41
3

I believe you need to add an initializer file with the require statement in it, for example if your lib file is /lib/some_module.rb you would need to create an initialiser file in /config/initializers/require_libs.rb...

# /config/initializers/require_libs.rb
require 'some_module'
roboles
  • 876
  • 6
  • 6