3

I've been googling around for tutorials on how to use Ruby on Rails with PostgreSQL. There is some pretty good info out there, but almost every guide is focused on how to configure Rails to use Postgres in development and test environments. They will warn you not to use these configurations for production, but not mention what you should do instead.

On the Postgres side, I would like to know what role I need to give to the Postgres user that Rails will connect to the database with. Also, I assume I would use environment variables in Rails for the DB credentials. Should I use ENV['DATABASE_URL'] in my database.yml? What does this pattern typically look like?

I'm using Rails 4.1.0 with PostgreSQL 9.1.13 on Ubuntu 12.04.2.

1 Answer 1

2

I recommend the gem figaro to manage your environment variables.

Where are you hosting your app? In Heroku you just need to set your database.yml like this:

production:
   adapter: postgresql
   encoding: unicode
   database: yourappname_production
   pool: 5
   username: root
   password: 

And you should have these gems added to your Gemfile:

gem 'pg'
gem 'activerecord-postgresql-adapter'

then you just deploy and everything is set for you.

Hope it helps

Sign up to request clarification or add additional context in comments.

1 Comment

I'm using the dotenv to manage my environment variables right now. I'll check out Figaro though. My app isn't actually hosted anywhere yet. I'm configuring it on a VM. I'm using it as an exercise in order to learn how to set up a Rails server with Chef. The point of the exercise is to learn how to configure everything from scratch, so I probably won't be using Heroku, although normally that would be a great option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.