Rails 无法生成页面,没有"config/database.yml"

终端报错

$rails g controller welcome

/Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/application/configuration.rb:143:in `database_configuration': Cannot load `Rails.application.database_configuration`:

Could not load database configuration. No such file - ["config/database.yml"] (RuntimeError)

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/railtie.rb:122:in `block (2 levels) in '

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:44:in `each'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/base.rb:324:in `'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/base.rb:24:in `'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:338:in `active_record_configured?'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:259:in `disconnect_database'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:97:in `preload'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:143:in `serve'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'

from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `'

from /Users/lvchengbo/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /Users/lvchengbo/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from -e:1:in `<main>`

解决办法

运行命令,生成文件 config/database.yml

touch config/database.yml

贴进去

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,850评论 19 139
  • linux资料总章2.1 1.0写的不好抱歉 但是2.0已经改了很多 但是错误还是无法避免 以后资料会慢慢更新 大...
    数据革命阅读 14,272评论 2 33
  • 熊志军~【日精进打卡第494天】 9月19号卡 付达新商贸~众德营销 沈阳盛和塾道盛组/稻芽七组 【知~学习】 无...
    熊志军阅读 1,720评论 0 1
  • 下面带来的是一组慵懒气质的中长卷发,喜欢的妹子一定不要错过,换上准能美出新高! 这种慵懒气质的中长卷发是真的很好看...
    阿明老师阅读 5,472评论 0 1
  • 她开了一家糖水店。店面不大,装修却委实有趣,加之门口一盏随风摇曳叮当作响的淡紫风铃,总吸引着行行色色疲于生活的都市...
    胥清离阅读 2,629评论 0 3

友情链接更多精彩内容