views:

215

answers:

1

My app works pretty much perfectly in production – the website part of it, at least. The problem only pops up when I SSH into my VPS and do "rails c RAILS_ENV=production". The console works fine in development mode.

I've had this problem before (or at least one that looks like it) and fixed it by adding "reconnect: true" to database.yml – but it didn't fix it this time around. Here's the start of the error output:

/home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in `establish_connection': RAILS_ENV=production database is not configured (ActiveRecord::AdapterNotSpecified)
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/railtie.rb:59:in `block (2 levels) in <class:Railtie>'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/railtie.rb:57:in `block in <class:Railtie>'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `instance_exec'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `run'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:50:in `block in run_initializers'

And for my production database settings:

production:
  adapter: mysql
  encoding: utf8
  database: tour_production
  pool: 5
  username: [user]
  password: [password]
  socket: /var/run/mysqld/mysqld.sock
  reconnect: true

I can't get my mind around why it works through passenger, but no luck with the console. Anyway, I'm using Rails 3, Ruby 1.9.2, Passenger and Nginx.

I've been doing some little stuff through Runner, which is annoying. I'd like to get this fixed. So thanks a bunch for any help.

+2  A: 

When you are using the console you specify the environment as the first argument rather than as an environment variable. So:

ruby script/console production

will load the production environment.

Your error message is because it is looking for the environment RAILS_ENV=production rather than just production.

Shadwell
Ah, that would do it. It seems like every command has a different way of declaring the rails environment. Thanks a bunch for the quick answer.
Nathan