Forum: Ruby on Rails Where to put general utility functions?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ingo W. (Guest)
on 2006-04-27 10:27
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.
Alex Y. (Guest)
on 2006-04-27 10:55
(Received via mailing list)
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
Ingo W. (Guest)
on 2006-04-27 13:09
> 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
Tom M. (Guest)
on 2006-04-27 13:46
(Received via mailing list)
You need to name the file:

lib/utilities.rb

--
-- Tom M.
This topic is locked and can not be replied to.