在生产中使用Postgres配置Rails

编程入门 行业动态 更新时间:2024-10-25 16:22:28
本文介绍了在生产中使用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

本文发布于:2023-05-31 10:04:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/389535.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Postgres   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!