christo16
christo16

Reputation: 4843

Rails- How can I use simple ruby classes?

I have some simple ruby classes that I want to use with rails (they are classes for things like points, lines, rectangles, etc.). How can I use them with a rails controller or an active record model?

Thanks!

Upvotes: 1

Views: 200

Answers (1)

coreyward
coreyward

Reputation: 80140

The convention is to put them in your-app/lib/. You can have Rails automatically load them by configuring it to do so in config/application.rb. Edit the default to look something like this:

# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W( #{Rails.root}/lib/shapes )

Where your class definition files are in your-app/lib/shapes.

Note: This is for Rails 3. Rails 2.x automatically loads files from lib.

Upvotes: 6

Related Questions