OK, I've been chasing this for hours and I just can't figure it out. I have a Ruby on Rails application that I've deployed to my hosting provider DreamHost. I've created a new environment called "stage" and created a stage.rb file in the /config/environment folder and put the following line into my environment.rb
# Be sure to restart your server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
ENV["RAILS_ENV"] ||= "stage"
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
I am able to run
RAILS_ENV=stage script/console
and everything runs fine. I can run rake db:migrate and generate my database. I can then drop into the console and act upon my model. I can also see the ActiveRecord activity in stage.log
The problem is when I open a browser and navigate to the URL I get the 500 error of
We're sorry, but something went wrong.
When I try to access the site through a browser I don't see anything written to stage.log.
My apache log file looks like this.
1.1.1.1 - - [19/Jan/2010:06:05:01 -0800] "GET /classes/calendar HTTP/1.1" 500 861 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.21.8 (KHTML, like开发者_JS百科 Gecko) Version/4.0.4 Safari/531.21.10"
I've even tried running the application controllers from the console and that works too. I just can't figure out why the page won't serve properly from a browser.
Is there a permission setting that I'm missing. I think on DreamHost the FTP user and the user that the server runs under are the same so I think I have the correct permissions but I'm just not sure.
Any help would be appreciated, Rob
The problem is likely in your line setting RAILS_ENV to "stage". The ||= assignment you are using sets a value only if RAILS_ENV is not yet defined. In this case, RAILS_ENV has most likely already been set to 'production' by DH even before hitting your app, so the ||= assignment has no effect.
To see whether this is really the issue, take a look at your logs directory - you'll probably find a production.log and no entries in stage.log (apart from the ones arising from your running script/console) since your app is being (unintentionally) run as production.
One way around this is to change the line to simply:
ENV["RAILS_ENV"] = "stage"
Usually this problem can be permissions on the scripts, or your gem enviroment. I'm not familiar with deployment of rails apps on DH, are you using Passenger or fastcgi?
From the shell, check your gem environment by running gem env
:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.8
- /home/<username>/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://gems.github.com", "http://gemcutter.org"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gems.github.com
- http://gemcutter.org
These settings apply from the console, but not when running via apache. For that, you need to edit config/environments.rb and add
ENV['GEM_PATH'] = '/home/<usrname>/.gem/ruby/1.8:/usr/lib/ruby/gems/1.8'
You want to make sure what you set as the GEM_PATH here matches what is output from the gem env command.
精彩评论