How do you include lib files

I have some additional Array methods I would like to make available, but
I can't figure out how to load them.

Thanks for the help.

require the file containing them.

Fred

Well files in config/initializers are run on startup, you could require it from there, other than that you are going to have to put that require statement somewhere.

Fred

Frederick Cheung wrote:

Chris Olsen wrote:

Which is what I did. I thought rails provided a way to auto load them at startup.

The auto loader only works like this. Here's the first time the interpreter sees Foo:

   foo = Foo.new

That raises an exception which Rails catches. Then it tries to require 'foo', based on the missing constant name.

That trick works only for things with a name. If foo.rb contains Bar, then the first instance of Bar, before a Foo, for any given interpretation, will not load foo.rb, and will propagate the exception.

You gotta remember this rule when building libraries. You could ensure Foo appears above Bar in every module, or you could require 'foo' explicitly.

And we put extensions to Ruby classes in environment.rb, but that might just be laziness!

did you try with require 'lib/yourfile' in the application.html.erb
file?