where to save a module?


I wrote a module which contains some methods for doing math functions.
I want the module to be included in one of my rails models.

Where is the best place to put it?

if you put it under RAILS_ROOT/lib directory and assuming the name of the file and the name of the module match, then it will be automatically added by rails to the load_path and you can use it directly throughout your rails application.

in recent versions of rails you can also add directories to the load_path directly by tweaking environment.rb (look at the code, there is a commented out example in there). But if we want convention over configuration i'd recommend lib.

about making it a gem/plugin, I'd only do it if it's going to be something really generic that you are going to be reusing in several projects. If not, it's not worth the overwork.


javier ramirez

Really up to you. Probably the only reason to put them into
ActiveRecord is if you want to persist them to ActiveRecord store and
have them updateable at some time in the future.