Rails 無(wú)法生成頁(yè)面,沒(méi)有"config/database.yml"

終端報(bào)錯(cuò)

$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>`

解決辦法

運(yùn)行命令,生成文件 config/database.yml

touch config/database.yml

貼進(jìn)去

# 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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,695評(píng)論 19 139
  • linux資料總章2.1 1.0寫(xiě)的不好抱歉 但是2.0已經(jīng)改了很多 但是錯(cuò)誤還是無(wú)法避免 以后資料會(huì)慢慢更新 大...
    數(shù)據(jù)革命閱讀 13,353評(píng)論 2 33
  • 熊志軍~【日精進(jìn)打卡第494天】 9月19號(hào)卡 付達(dá)新商貿(mào)~眾德?tīng)I(yíng)銷(xiāo) 沈陽(yáng)盛和塾道盛組/稻芽七組 【知~學(xué)習(xí)】 無(wú)...
    熊志軍閱讀 271評(píng)論 0 1
  • 下面帶來(lái)的是一組慵懶氣質(zhì)的中長(zhǎng)卷發(fā),喜歡的妹子一定不要錯(cuò)過(guò),換上準(zhǔn)能美出新高! 這種慵懶氣質(zhì)的中長(zhǎng)卷發(fā)是真的很好看...
    阿明老師閱讀 1,653評(píng)論 0 1
  • 她開(kāi)了一家糖水店。店面不大,裝修卻委實(shí)有趣,加之門(mén)口一盞隨風(fēng)搖曳叮當(dāng)作響的淡紫風(fēng)鈴,總吸引著行行色色疲于生活的都市...
    胥清離閱讀 377評(píng)論 0 3

友情鏈接更多精彩內(nèi)容