【问题标题】:recompiling database.yml file with gemfile? ruby on rails用 gemfile 重新编译 database.yml 文件?铁轨上的红宝石
【发布时间】:2014-03-10 06:36:51
【问题描述】:
我是 Ruby on Rails 和 postgreSQL 的新手,有一个问题。在 Gemfile 上运行 bundle install 时是否会编译 database.yml 文件?最初我的 gemfile 有 sqlite3,但我将其更改为 pg 并尝试再次运行bundle install 以重新编译 database.yml 文件,但该文件仍然说它正在使用 SQLite。
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
我希望将适配器切换到postgresql,并且我相信在使用 pg 时应该切换其他一些字段,但我不确定。谁能帮我解释一下,谢谢。
【问题讨论】:
标签:
ruby-on-rails
postgresql
gemfile
pg
【解决方案1】:
不,database.yml 不会自动重新编译。更改Gemfile中的gem时,还需要更改文件:
development:
adapter: postgresql
database: dbname
username: user
password: password
encoding: unicode
【解决方案2】:
您也需要替换 config/database.yml 中的适配器值
当您运行 bundle install 时,它将安装在您的 Gemfile 中声明的 gem,但您必须手动设置数据库配置。除了声明 gem 版本的 Gemfile.lock 之外,Bundle 不会在您的应用程序上编译您的任何内容。
类似:
development:
adapter: postgresql
encoding: unicode
database: myapp_development
host: localhost
password: password # if you need a password
test:
adapter: postgresql
encoding: unicode
database: myapp_test
host: localhost
password: password # if you need a password
production:
adapter: postgresql
encoding: unicode
database: myapp_production
host: localhost
password: password # probably you will need a password