Where to put general utility functions?

Hi,

I have a bunch of utility functions. If I put them in
“controllers/application.rb” then they will be accessible from all
controllers. If I put them in “helpers/application_helper.rb” then they
will be accessible from all templates.

But what if I need to access them from everywhere - controllers, views,
even models? Where do I put them?

Ingo W.

Ingo W. wrote:

Hi,

I have a bunch of utility functions. If I put them in
“controllers/application.rb” then they will be accessible from all
controllers. If I put them in “helpers/application_helper.rb” then they
will be accessible from all templates.

But what if I need to access them from everywhere - controllers, views,
even models? Where do I put them?

Sling’em in lib/. They’ll get automatically required.


Alex

Sling’em in lib/. They’ll get automatically required.

Now I have a file “lib/utilities”, with my function definitions in it. I
still get a “no method” error when attempting to use the functions. Is
there anything else I need to do?

Ingo

You need to name the file:

lib/utilities.rb


– Tom M.