views:

22

answers:

2

Where do most Rails apps usually keep their non-active-record classes?

In app/models? In lib/some_file.rb?

Someplace else?

A: 

If you put your files in app/models, they'll be reloaded along with all other models. This eases development. In app/models, I have:

acts_as_bookable.rb
subclass_responsibility_error.rb
user.rb

To Rails, app/models is just a location from which it reloads.

François Beausoleil
+1  A: 

It depends what is the purpose of this class. If this is something like a model. On example, by default mailers are put in app/models and it isn't ActiveRecord. If you want to add some classes that are used in your application in many places and it isn't model-related, then probably the best place is to put it in a lib directory. If you want to reuse it, you can also create a plugin with your class and then it would be placed in vendor/plugins.

You can also put it in config/initializers if it fits into this category.

To sum up: it depends what your class is about. Put it in a place where it fits. If you have doubts, put it in lib directory.

klew