# Where to put my homegrown class?

**URL:** <https://www.ruby-forum.com/t/where-to-put-my-homegrown-class/66204>\
**Category:** Rails\
**Created:** [August 23, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/where-to-put-my-homegrown-class/66204 "2006-08-23T22:54:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philip\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c5a1d2/32.png) [@Philip\_N](https://www.ruby-forum.com/u/Philip_N)\
**Post date:** [August 23, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/where-to-put-my-homegrown-class/66204/1 "2006-08-23T22:54:35Z")

</div>

I’ve developed a file (let’s call it mypdf.rb) which extends the module  
PDF::Writer with some additional methods. This enables me to produce  
PDF  
documents of a very specific nature for a project I am working on.

I’ve developed and tested this outside the RoR framework. Now I want  
to use  
it within the context of a RoR application.

Where should I put the mypdf.rb file, so that I can define objects from  
the  
class ? Somewhere within the RoR application framework code ? Or  
somewhere in the Ruby install tree ?

TIA

Phil Nelson

---

<div class="post-metadata">

**Author:** ![Philip\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c5a1d2/32.png) [@Philip\_N](https://www.ruby-forum.com/u/Philip_N)\
**Post date:** [August 23, 2006, 11:05pm UTC](https://www.ruby-forum.com/t/where-to-put-my-homegrown-class/66204/2 "2006-08-23T23:05:41Z")

</div>

Philip N. wrote:

> I’ve developed a file (let’s call it mypdf.rb) which extends the module  
> PDF::Writer with some additional methods. ï¿½ This enables me to produce  
> PDF  
> documents of a very specific nature for a project I am working on.
> 
> I’ve developed and tested this outside the RoR framework. ï¿½ Now I want  
> to use  
> it within the context of a RoR application.
> 
> Where should I put the mypdf.rb file, so that I can define objects from  
> the  
> class ? ï¿½ Somewhere within the RoR application framework code ? ï¿½ Or  
> somewhere in the Ruby install tree ?
> 
> TIA
> 
> Phil Nelson

Phil

You can put your mypdf.rb in \<Your\_App\_Root\>/lib and in your code you  
can do

require ‘lib/mypdf’

-daya

---

<div class="post-metadata">

**Author:** ![Philip\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c5a1d2/32.png) [@Philip\_N](https://www.ruby-forum.com/u/Philip_N)\
**Post date:** [August 23, 2006, 11:42pm UTC](https://www.ruby-forum.com/t/where-to-put-my-homegrown-class/66204/3 "2006-08-23T23:42:39Z")

</div>

On Aug 23, 2006, at 1:44 PM, Philip N. wrote:

> Where should I put the mypdf.rb file, so that I can define objects  
> from the  
> class ? Somewhere within the RoR application framework code ? Or  
> somewhere in the Ruby install tree ?

rails\_root/lib

–  
Chris W.

> **[err.the\_blog](http://errtheblog.com)**
>
> Err the Blog: Ruby and Rails from the front.

---

<div class="post-metadata">

**Author:** ![Philip\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c5a1d2/32.png) [@Philip\_N](https://www.ruby-forum.com/u/Philip_N)\
**Post date:** [August 24, 2006, 9:03am UTC](https://www.ruby-forum.com/t/where-to-put-my-homegrown-class/66204/4 "2006-08-24T09:03:24Z")

</div>

On 8/23/06, Daya S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Phil
> 
> You can put your mypdf.rb in \<Your\_App\_Root\>/lib and in your code you  
> can do
> 
> require ‘lib/mypdf’

I am 95% sure that if you put the class in the root of lib (_not_ in a  
subdirectory) it will be autoloaded by Rails initializer. So don’t  
need the explicity require. At least with version 1.1.6.

- rob  
–  
[http://www.robsanheim.com](http://www.robsanheim.com)  
[http://www.seekingalpha.com](http://www.seekingalpha.com)  
[http://www.ajaxian.com](http://www.ajaxian.com)
