ENV['myval'] is not processed under lsapi

Discussion in 'Ruby/Rails' started by dlhhyct, Sep 6, 2006.

  1. dlhhyct

    dlhhyct New Member

    in my <rail_root>/config/environment.rb, I set several global variables used throughout app. for example:
    Code:
    ENV['image_dir'] = '/folder1'
    ENV['record_click_trail'] = 'yes'
    when i try use those var in a controller or display the value in a rhtml page, eg, <%= ENV['image_dir'] %>
    * If rail app started under webrick or mongrel, they works fine.
    * under ruby lsapi, all of those var seems not processed and are nil when I try to use them.
  2. mistwang

    mistwang LiteSpeed Staff

  3. dlhhyct

    dlhhyct New Member

    u so fast

    thank you.
  4. mistwang

    mistwang LiteSpeed Staff

    You are welcome. :)
    Please let me know it is fixed or not. you may need to uninstall the gem first with "gem uninstall ruby-lsapi".
  5. dlhhyct

    dlhhyct New Member

    almost

    ENV[] values in environment.rb are recognized now. but config/environments/production.rb (test.rb, development.rb) can overwrite the same variable, which is not doing that under lsapi 1.7
  6. mistwang

    mistwang LiteSpeed Staff

    Are you sure? I believe values in environment.rb will override the value set in config/environments/producion.rb, etc. The same behavior under mongrel.
  7. dlhhyct

    dlhhyct New Member

    environment

    * environment.rb stores all variables used for the webapp.
    * environments/*.rb can choose to customize certain variables depends on environment.
    for example, in my environment.rb, i set ENV['image_dir']='/uploaded_images', which is same for all environments, but in my environment/test.rb, I can customize ENV['image_dir']='/tmp' since i don't need to keep image when running test cases.

    following is copy paste from agile RoR book, pg 238:
    ----------------------------------------------------------
    Environment files typically do three things
    * They set up the Ruby load path. This is how your application can find things such as models and views when it’s running.
    * They create resources used by your application (such as the logger).
    * They set various configuration options, both for Rails and for your application.

    The first two of these are normally application-wide and so are done in environment.rb. The configuration options often vary depending on the environment and so are likely to be set in the environment-specific files in the environments directory.
  8. mistwang

    mistwang LiteSpeed Staff

    I think it is a ruby bug or just the way it works. I cannot override a ENV[] variable in production.rb or development.rb if the same variable is set in environment.rb. Tried mongrel, same result.
    I tried ruby 1.8.4, 1.8.5 and rails 1.1.6.
    What's yours?
  9. dlhhyct

    dlhhyct New Member

    thank you

    you are right. only if i comment out same var in the environment.rb, then var in each env are read. i guess no overriding then, but that was the impression i got from the doc. I guess I should just leave the main environment.rb alone. Thank you.

Share This Page