如何在 Rails 中设置 database.yml 文件? [英] How do I set up the database.yml file in Rails?

查看:59
本文介绍了如何在 Rails 中设置 database.yml 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习本教程 (http://dmix.ca/2008/09/how-to-scrape-websites-in-ruby-on-rails-using-scrubyt/),开始之前的第 4 步是设置 database.yml 文件.不确定那是什么意思.有人可以解释一下吗?

I'm doing this tutorial (http://dmix.ca/2008/09/how-to-scrape-websites-in-ruby-on-rails-using-scrubyt/) and step 4 before I begin is to set up the database.yml file. Not sure what that means. Could someone please explain?

推荐答案

database.yml 是您设置连接数据库的所有信息的文件.它因您使用的数据库类型而异.您可以在 Rails 指南 或任何解释说明的教程中找到更多信息如何设置 Rails 项目.

The database.yml is the file where you set up all the information to connect to the database. It differs depending on the kind of DB you use. You can find more information about this in the Rails Guide or any tutorial explaining how to setup a rails project.

database.yml 文件中的信息由环境限定,允许您为测试、开发或生产获得不同的设置.如果您不希望在运行测试套件时错误地删除用于开发的数据,那么保持这些数据的区别非常重要.

The information in the database.yml file is scoped by environment, allowing you to get a different setting for testing, development or production. It is important that you keep those distinct if you don't want the data you use for development deleted by mistake while running your test suite.

关于源代码控制,您不应提交此文件,而应为其他开发人员创建一个模板文件(称为 database.yml.template).部署时,约定是直接在服务器上的/shared/config中创建这个database.yml文件.

Regarding source control, you should not commit this file but instead create a template file for other developers (called database.yml.template). When deploying, the convention is to create this database.yml file in /shared/config directly on the server.

使用 SVN:svn propset svn:ignore config "database.yml"

使用 Git:将 config/database.yml 添加到 .gitignore 文件或使用 git-extra git ignore config/database.yml

With Git: Add config/database.yml to the .gitignore file or with git-extra git ignore config/database.yml

...现在,一些例子:

... and now, some examples:

SQLite

adapter: sqlite3
database: db/db_dev_db.sqlite3
pool: 5
timeout: 5000

MYSQL

adapter: mysql
database: my_db
hostname: 127.0.0.1
username: root
password: 
socket: /tmp/mysql.sock
pool: 5
timeout: 5000

带有 MongoID 的 MongoDB(称为 mongoid.yml,但基本相同)

host: <%= ENV['MONGOID_HOST'] %>
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
# slaves:
#   - host: slave1.local
#     port: 27018
#   - host: slave2.local
#     port: 27019

这篇关于如何在 Rails 中设置 database.yml 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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