What does this represent : ENV["_"]

Hi,

Does somebody know to what the following exactly refers to?

ENV["_"]

I have read about ‘ENV[“RAILS_ENV”]’ but don’t understand the above
mentioned.

-> Is this something defined by Rails itself or is it some custom
variable?
-> In my case, a plugin doesn’t work because ENV["_"] is ‘nil’. Do you
have an idea why? Or how could I circumvent that problem to make the
plugin work anyway?

Thank you in advance for any hint!
Tom

Forgot to add: this variable occurs in the following line:

require File.join(File.dirname(ENV["_"]), ‘…/config/environment.rb’)

-> What does that try to do exactly? What file exactly does it try to
‘require’?

ENV is a hash-like something or other provided by ruby to give access to
environment variables. That looks like a strange name for an
environment variable–not sure what your plugin is going for there…

I believe ENV["_"] is the built in rails constant that points to the
environment.rb file location

require File.join(File.dirname(ENV["_"]), ‘…/config/environment.rb’)
is a “require” statement for the environment.rb file

File.join is concatinating the “dirname” part or the environment file
location
Windows example (C:rails_projects/myproject)

with …/config/environment.rb’

to get:
require C:rails_projects/myproject/config/environment.rb

Thanks a lot, dudes!

Ah, a bit more info–the underbar environment variable looks to be a
unix thing. Or at least–on my windows box, I get nil back from ruby if
I do a one-line “puts(ENV[’_’])” via a DOS box, but doing the same via a
cygwin bash prompt I get back the path to the ruby executable
(/usr/bin/ruby).

Soooo–I’m guessing the original poster is running on windows, and his
plugin author was on something unixy.

But definitely the plugin is looking to include the environment.rb file
for the currently running rails app. Not totally sure how to make that
cross-platform friendly… I suppose you could hard-code it if you can
deal with that dirty feeling that won’t wash off. :wink:

<Ah, a bit more info–the underbar environment variable looks to be a
<unix thing

That’s good to know as I cross-dress between ubuntu and XP

Play with
puts ENV or p ENV (which should print the entire hash)
etc to see what you get and maybe just replace

‘ENV["_"]’ with ‘ENV[“RAILS_ENV”]’ or what ever seems to be the
enviroment path in ENV

(You probably already did that)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs