RAILS_ENV revisited

Discussion in 'Ruby/Rails' started by ostraaten, Dec 17, 2007.

  1. ostraaten

    ostraaten Member

    I have my Rails app setup on LiteSpeed by instantiating a virtual host I created using the Rails template.

    Now I want to create two environment for the same app. A staging environment and a production environment.

    What is still not clear to me is how the RAILS_ENV can be set. Should I create a external app under my vhost definition so I can specify the RAILS_ENV?

    There I have the option of specifying environment options so I could add for instance RAILS_ENV=staging?

    If this is the way to go, what should I add for the 'command' variable?
    Thanks and Regards,
  2. mistwang

    mistwang LiteSpeed Staff

  3. ostraaten

    ostraaten Member

    Where is dispatch.lsapi

    When I try to add this external app I see an error message:
    *file /home/user/site/staging/current/public/dispatch.lsa pi does not exist. Please create manually.

    Where can I find this file? Should I create one myself? What should it contain?

    My context list now has two entries
    Rails / 2 + / - View Edit Delete
    LiteSpeed API /dispatch.lsapi 1 + / - View Edit Delete

    The context I added seems to make a difference. But now it produces an error message 403 Forbidden?
  4. i_am_cam

    i_am_cam New Member

    Having just set up a staging environment last week, I may be able to help. :)

    The dispatch.lsapi file I took from the lsapi gem directory, but here's the contents of it (note I've changed the location of ruby to match where it's installed on my server - you may have to change this).

    Remember to set the file to be executable!

    require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
    # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
    # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
    require "dispatcher"
    require "lsapi"
    while LSAPI.accept != nil
  5. ostraaten

    ostraaten Member

    I think this should be simpler. Doing all this just to set RAILS_ENV? There should be an easier way to do this that won't require you to add an external app, a context, rewrite rules, a dispatch.lsapi file.

    The 'Rails' context should allow other options than 'development' and 'production'. This field should be displayed as an ordinary text field and not a list box. This would be my enhancement request for LiteSpeed.

    With this version of LiteSpeed I recommend the following approaches that keep things as simple as they should be.

    1. use 'development' for your staging requirement
    2. use your deployment script to manually set the environment in environment.rb

    I prefer approach 1 as it doesn't require any tricks as 'development' is a supported RAILS_ENV. This will require you to keep the 'development' env on your client and the 'development' env on the server in sync. That is maybe not even a small price to pay but what you have to do anyway?

    I tried approach 2, this also works fine and requires you only to search and replace the environment specified in environment.rb e.g. in my Capfile I added this line to my restart task:

        run "sed -i 's/production/staging/g' #{deploy_to}/current/config/environment.rb" if "#{rails_env}" == 'staging'
  6. mistwang

    mistwang LiteSpeed Staff

    How about add "staging" to the list, seems most people prefer this. Letting user input arbitrary text may open another can of worm. :)
  7. i_am_cam

    i_am_cam New Member

    That would be appreciated, mistwang :)
  8. ostraaten

    ostraaten Member

    One extra environment 'staging' that would be great. I vote yes.

Share This Page