在生产中使用Postgres配置Rails [英] Configuring Rails Using Postgres in Production

查看:100
本文介绍了在生产中使用Postgres配置Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找有关如何在PostgreSQL上使用Ruby on Rails的教程。那里有一些很好的信息,但是几乎每本指南都集中在如何配置Rails以便在开发和测试环境中使用Postgres上。他们会警告您不要在生产中使用这些配置,但不要提及您应该做的事情。

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.

在Postgres方面,我会想知道我需要给Rails用来连接数据库的Postgres用户扮演什么角色。另外,我假设我将在Rails中使用环境变量作为数据库凭据。我应该在我的database.yml中使用 ENV ['DATABASE_URL'] 吗?这种模式通常是什么样的?

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?

我在Ubuntu 12.04.2。上使用Rails 4.1.0和PostgreSQL 9.1.13

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

推荐答案

我推荐 gem figaro 管理环境变量。

您在哪里托管应用程序?在 Heroku 中,您只需要像这样设置您的database.yml:

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: 

您应该将以下gem添加到Gemfile中:

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.

希望它会有所帮助

这篇关于在生产中使用Postgres配置Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆