Where to save a module?

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

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 !!Es gratis!!

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 !!Es gratis!!

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 [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs