Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Rails to work with the production database (rather than development one) when deploying?

I'm trying to upload my Rails 3 application to real production environment. (The application works perfectly on my local machine).

When I run rails c I got the following error:

/home/misha_moroshko/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in `establish_connection': development database is not configured (ActiveRecord::AdapterNotSpecified)
        from /home/misha_moroshko/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
        from /home/misha_moroshko/.gems/gems/activerecord-3.0.1/lib/active_record/railtie.rb:59
        from /home/misha_moroshko/.gems/gems/activesupport-3.0.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'

How should I tell Rails that it should work with the production database rather than the development one ?

like image 941
Misha Moroshko Avatar asked Mar 25 '11 06:03

Misha Moroshko


People also ask

What three databases are referred to by a Rails application?

Ruby on Rails recommends to create three databases - a database each for development, testing, and production environment. According to convention, their names should be − library_development. library_production. library_test.

What is the default Rails environment?

Rails ships with a default configuration for the three most common environments that all applications need: test, development, and production.


3 Answers

Set the RAILS_ENV environment variable first, or pass it to the rails c command:

RAILS_ENV=production rails c

OR

rails c production
like image 123
ctcherry Avatar answered Nov 09 '22 15:11

ctcherry


what's in your database.yml? it should have a production setting and you'll need to tell rails you want to run it in production:

rails c production
like image 43
corroded Avatar answered Nov 09 '22 14:11

corroded


This depends greatly on the 'environment' you are deploying to. For Apache and Passenger, one would set:

# conf/passenger.conf
RailsEnv production
RackEnv production
like image 1
Kevin Sylvestre Avatar answered Nov 09 '22 13:11

Kevin Sylvestre