Saurabh Shah
Saurabh Shah

Reputation: 606

ActiveRecord in production mode without rails

I want to use activerecord without rails. I know that in rails we can use the production mode as RAILS_ENV=production but how do I use production mode in activerecord without rails?

Upvotes: 0

Views: 320

Answers (2)

Raj
Raj

Reputation: 22926

  1. Create one YML file or any properties file to store database properties for each of your environment.
  2. While starting your non-rails app, start with a environment variable like APP_ENV=production
  3. In your application code, use this environment variable & read the appropriate file and pass to ActiveRecord
environment = ENV['APP_ENV'] || 'development'
puts "Connecting to #{environment} database"
ActiveRecord::Base.establish_connection YAML.load_file(config)[environment]

Upvotes: 1

tpbowden
tpbowden

Reputation: 2090

The way you connect to your database is up to you, you just have to supply the credentials. If you want to implement something like config/database.yml without Rails you will have to do it yourself, and you can use an environment variable of your choice to specify which key in the file to read.

Upvotes: 0

Related Questions