# Where to save a module?

**URL:** <https://www.ruby-forum.com/t/where-to-save-a-module/93094>\
**Category:** Rails\
**Created:** [April 27, 2007, 12:46pm UTC](https://www.ruby-forum.com/t/where-to-save-a-module/93094 "2007-04-27T12:46:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris\_finch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/2bfe46/32.png) [@chris\_finch](https://www.ruby-forum.com/u/chris_finch)\
**Post date:** [April 27, 2007, 12:46pm UTC](https://www.ruby-forum.com/t/where-to-save-a-module/93094/1 "2007-04-27T12:46:57Z")

</div>

Hi all,

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?  
Should I make it into a gem and do a gem install

- or can I just put it somewhere in the rails directory?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![chris\_finch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/2bfe46/32.png) [@chris\_finch](https://www.ruby-forum.com/u/chris_finch)\
**Post date:** [April 27, 2007, 1:26pm UTC](https://www.ruby-forum.com/t/where-to-save-a-module/93094/2 "2007-04-27T13:26:28Z")

</div>

hi,

> 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.

Regards,

javier ramirez

## –

Estamos de estreno… si necesitas llevar el control de tus gastos  
visita [http://www.gastosgem.com](http://www.gastosgem.com) !!Es gratis!!

---

<div class="post-metadata">

**Author:** ![chris\_finch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/2bfe46/32.png) [@chris\_finch](https://www.ruby-forum.com/u/chris_finch)\
**Post date:** [April 27, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/where-to-save-a-module/93094/3 "2007-04-27T15:12:59Z")

</div>

thanks Javier, that’s just the ticket.

I have another question:  
Before I converted it into a rails app, my app used a yaml file and a  
csv file to lookup numbers for the math functions.  
How do these files translate into a rails app? - should I keep them as  
yaml and csv or can I change them into some sort of Active Record  
models?

thanks,  
Chris

javier ramirez wrote:

> hi,
> 
> > 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.
> 
> Regards,
> 
> javier ramirez
> 
> ## –
> 
> Estamos de estreno… si necesitas llevar el control de tus gastos  
> visita [http://www.gastosgem.com](http://www.gastosgem.com) !!Es gratis!!

---

<div class="post-metadata">

**Author:** ![chris\_finch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/2bfe46/32.png) [@chris\_finch](https://www.ruby-forum.com/u/chris_finch)\
**Post date:** [April 27, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/where-to-save-a-module/93094/4 "2007-04-27T17:41:33Z")

</div>

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.

On Apr 27, 9:12 pm, chris finch [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
