views:

209

answers:

2

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 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

A: 

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.

Jeff Paquette
The only difference I have in my gem version compared to yours is this RUBY VERSION: 1.8.5 (2006-08-25) [x86_64-linux]I added the line ENV['GEM_PATH'] = '/home/<username here>/.gem/ruby/1.8:/usr/lib/ruby/gems/1.8'to my stage.rb file and ran the webpage again with the same result. 500 Error with no log information.
Rob Jefferies
Forgot to say that DreamHost uses Passenger.
Rob Jefferies
Obvious questions... you put your username in for <username> , and restarted your app (`touch tmp/restart.txt`) ? Did you check logs/stage.log as well?
Jeff Paquette
Yes I put the real username instead of <username>. Stupid question. I run my local dev using Mongrel. It doesn't have a restart.txt in the tmp folder. Does this mean I need to create the restart.txt file int he /tmp folder? I'm assuming you mean the rails /tmp folder. Also there is nothing getting written to the log/stage.log when going through the browser. Only when I run the app through the console.
Rob Jefferies
In your rails dir, just `touch tmp/restart.txt` and on the next request to your app, Passenger will restart it. As for the logs, are any logs being written to when you run via the browser?
Jeff Paquette
No rails logs seem to be written to via the browser (only under the console). The apache log is being written to with a row similar to the one above. After some additional research I noticed that one of my working sites is running under Ruby 1.8.7 and this one is 1.8.5. Would that make a difference? It doesn't seem like it should since the app runs under the console. Would the passenger layer be different enough that an error could be happening in there that I'm not seeing? Thanks for your comments flyfish64. I'm really appreciating the help.
Rob Jefferies
One more thing to try... change `ENV["RAILS_ENV"] ||= "stage"` to `ENV["RAILS_ENV"] = "stage"`. ||= will only set it if it's not set. Also, this http://craigjolicoeur.com/blog/set-rails_env-for-phusion-passenger-on-dreamhost may help
Jeff Paquette
Did you get this working?
Jeff Paquette
+1  A: 

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"
Steven