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.
3504745159d79c585e4f7df8df76aa10?d=identicon&s=25 Ingo Weiss (ingoweiss)
on 2006-04-27 08: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 Weiss
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-04-27 08:55
(Received via mailing list)
Ingo Weiss 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
3504745159d79c585e4f7df8df76aa10?d=identicon&s=25 Ingo Weiss (ingoweiss)
on 2006-04-27 11: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
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-04-27 11:46
(Received via mailing list)
You need to name the file:

lib/utilities.rb

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