ruby-on-rails – rails4 – Psych :: BadAlias:未知别名:test

尝试使用Capistrano cap deploy部署我的项目:迁移,我在我的 database.yml上的测试别名中出错(这在本地服务器上运行正常)
development:
   database: db_dev
   adapter: MysqL2
   username: xxxxxx
   password: xxxxxx
   host: localhost
   encoding: utf8

test: &test
   database: db_test
   adapter: MysqL2
   username: xxxxxx
   password: xxxxxx
   host: localhost
   encoding: utf8

production:
   database: db_prod
   adapter: MysqL2
   username: xxxxxxxx
   password: xxxxxxx
   host: localhost
   encoding: utf8

cucumber:
   <<: *test

控制台日志是:

rake aborted!
   Psych::Badalias: UnkNown alias: test
   /railties-4.0.3/lib/rails/application/configuration.rb:106:in `database_configuration'
   /activerecord-4.0.3/lib/active_record/railtie.rb:175:in `block (2 levels) in <class:Railtie>'
   /activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
   /activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
   /activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
   /activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:27:in `each'
   /activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
   /activerecord-4.0.3/lib/active_record/railtie.rb:174:in `block in <class:Railtie>'
   /railties-4.0.3/lib/rails/initializable.rb:30:in `instance_exec'
   /railties-4.0.3/lib/rails/initializable.rb:30:in `run'
   /railties-4.0.3/lib/rails/initializable.rb:55:in `block in run_initializers'
   /railties-4.0.3/lib/rails/initializable.rb:54:in `run_initializers'
   /railties-4.0.3/lib/rails/application.rb:215:in `initialize!'
   /railties-4.0.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
   /home/kadoudal/rails/swim-tech.eu/site/swimtech/releases/20140326140458/config/environment.rb:6:in `<top (required)>'
   /activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require'
   /activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `block in require'
   /activesupport-4.0.3/lib/active_support/dependencies.rb:214:in `load_dependency'
   /activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require'
   /railties-4.0.3/lib/rails/application.rb:189:in `require_environment!'
   /railties-4.0.3/lib/rails/application.rb:250:in `block in run_tasks_blocks'
   Tasks: TOP => db:migrate => environment

解决方法

我不相信您可以根据您引导的环境分配测试,开发或生产别名(如果环境是生产环境,则将应用生产设置).问题是,如果这样做,黄瓜只能在测试环境中使用.

我使用了类似于下面的东西:

base: &base
     adapter: MysqL2
     host: address.com
     encoding: utf8
     adapter: MysqL2
     username: xxxxxx
     password: xxxxxx

  development:
     database: db_dev
     <<: *base

  test:
     database: db_test
     <<: *base

  production:
     database: db_prod
     <<: *base

  cucumber:
     database: cucumber
     <<: *base

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...