Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you include a class from /lib into your code in app/controllers

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?

like image 865
Jason Kim Avatar asked Dec 28 '25 06:12

Jason Kim


1 Answers

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.

like image 153
keithepley Avatar answered Dec 30 '25 21:12

keithepley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!