I asked about this a few days ago and got no replies, so I’m asking
again.
I have a file called string_extensions.rb. In it, I extend the String
class
to include some extra functionality. I put this file into the lib/
directory
of my app.
But the changes made to String don’t take effect. The program acts as
though
the files aren’t being included.
I’ve stopped and restarted the server. No go. I tried including
Reloadable.
No go.
Is there something I’m missing? Seems like it should just work.
I asked about this a few days ago and got no replies, so I’m asking
again.
I have a file called string_extensions.rb. In it, I extend the String
class
to include some extra functionality. I put this file into the lib/
directory
of my app.
But the changes made to String don’t take effect. The program acts as
though
the files aren’t being included.
I’ve stopped and restarted the server. No go. I tried including
Reloadable.
No go.
Is there something I’m missing? Seems like it should just work.
I had this problem too. My solution was to require the file in
environment.rb
also, my file was called string.rb, I don’t know if that will make a
difference
Wow Ed. That’s a whole lot of work to include a file. Why not simply…
require “string_extensions” is sufficient
require “#{RAILS_ROOT}/lib/string_extensions”
What Alan suggested works fine, I just think it’s odd… why have those
directories… or maybe they’re NOT included by default, but simply provided
by default… as placeholders… Hmm…
lib is part of the load path, meaning that if you do require
“file_name” then it’ll search in the lib dir for the filename. It
exists so that you can put stuff in there and just require it into
your files without having to do any of that RAILS_ROOT crap. Just
like any Ruby app though, the file’s contents are loaded into memory
until you require it.
Wow Ed. That’s a whole lot of work to include a file. Why not simply…
require “#{RAILS_ROOT}/lib/string_extensions”
What Alan suggested works fine, I just think it’s odd… why have those
directories… or maybe they’re NOT included by default, but simply
provided
by default… as placeholders… Hmm…
Either way, thanks for the response Ed. By the way, my string extension
is…