# Where should I put my hand-coded classes

**URL:** <https://www.ruby-forum.com/t/where-should-i-put-my-hand-coded-classes/94359>\
**Category:** Rails\
**Created:** [May 1, 2006, 11:46pm UTC](https://www.ruby-forum.com/t/where-should-i-put-my-hand-coded-classes/94359 "2006-05-01T23:46:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 1, 2006, 11:46pm UTC](https://www.ruby-forum.com/t/where-should-i-put-my-hand-coded-classes/94359/1 "2006-05-01T23:46:43Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 2, 2006, 3:35am UTC](https://www.ruby-forum.com/t/where-should-i-put-my-hand-coded-classes/94359/2 "2006-05-02T03:35:18Z")

</div>

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

Joe

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 2, 2006, 7:42am UTC](https://www.ruby-forum.com/t/where-should-i-put-my-hand-coded-classes/94359/3 "2006-05-02T07:42:27Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 3, 2006, 6:58pm UTC](https://www.ruby-forum.com/t/where-should-i-put-my-hand-coded-classes/94359/4 "2006-05-03T18:58:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 3, 2006, 6:58pm UTC](https://www.ruby-forum.com/t/where-should-i-put-my-hand-coded-classes/94359/5 "2006-05-03T18:58:44Z")

</div>

These things generally go in /lib.

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/where-should-i-put-my-hand-coded-classes/94359/6 "2006-05-03T18:59:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 2, 2006, 8:09am UTC](https://www.ruby-forum.com/t/where-should-i-put-my-hand-coded-classes/94359/7 "2006-05-02T08:09:21Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 3, 2006, 7:00pm UTC](https://www.ruby-forum.com/t/where-should-i-put-my-hand-coded-classes/94359/8 "2006-05-03T19:00:48Z")

</div>

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
