Where should I put my hand-coded classes

I have a class that is hand-coded (not generated using generator).

Is there a preferred location for the file.

app/components ?

does it matter?

Thanks,

/lib I’m pretty sure. That’s where me puts 'em.

Joe

You should put them in RAILS_ROOT/lib if they are app specific. If you
plan to use them on multiple apps, consider writing a plugin.

Note: code in /lib is loaded only once so unless you use
require_dependency, you’ll have to restart the server when you make
changes. Also, it’s good practice to wrap your code in a module to
reduce the chance of a namespace collision.

Pradeep S. wrote:

I have a class that is hand-coded (not generated using generator).

Is there a preferred location for the file.

app/components ?

does it matter?

Thanks,

On Mon, May 01, 2006 at 11:46:43PM +0200, Pradeep S. wrote:

I have a class that is hand-coded (not generated using generator).

Is there a preferred location for the file.

app/components ?

does it matter?

Hey Pradeep,

Not components. Put it in lib/.

marcel

These things generally go in /lib.

Pradeep S. wrote:

Just a follow-up question.

I don’t see RAILS_ROOT/lib dir. does it suppose to exist by default or
do I need to create it with the first class.

Making sure, that I am looking at the right place.

RAILS_ROOT is a constant that identifies the root directory of your
application. It is the directory that contains the app, config, log,
public, script and vendor directories.

It should also contain lib, assuming you created your application with
rail, so you should not have to create it.

Ray

Just a follow-up question.

I don’t see RAILS_ROOT/lib dir. does it suppose to exist by default or
do I need to create it with the first class.

Making sure, that I am looking at the right place.

Thanks,

Steve R. wrote:

You should put them in RAILS_ROOT/lib if they are app specific. If you
plan to use them on multiple apps, consider writing a plugin.

Note: code in /lib is loaded only once so unless you use
require_dependency, you’ll have to restart the server when you make
changes. Also, it’s good practice to wrap your code in a module to
reduce the chance of a namespace collision.

Pradeep S. wrote:

I have a class that is hand-coded (not generated using generator).

Is there a preferred location for the file.

app/components ?

does it matter?

Thanks,

Steve R. wrote:

> Note: code in /lib is loaded only once so unless you use
> require_dependency, you'll have to restart the server when you 

make
> changes.

To avoid having to restart the server, I just make them reloadable:

# file: lib/foo.rb:
class Foo
    include Reloadable
    ...
end

Alain