当我使用heroku open时,我的web应用程序运行良好,但当我使用rails s(localhost)时,我遇到了以下错误:

ActiveRecord::AdapterNotSpecified database configuration does not specify adapter

这是为什么?

这是我的数据库.yml

# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On OS X with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: 5

这是我的档案:

source 'https://rubygems.org'


gem 'pg'

gem 'bootstrap-sass', '~> 3.1.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

group :production do
  gem 'rails_12factor', '0.0.2'
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

推荐答案

要让你的应用在本地运行,你需要:

  1. 你的机器上有Install Postgresql
  2. Create a database美元用于满足您的发展需求(我们称之为my_app_development美元)
  3. 将你的database.yml改为:

    default: &default
      adapter: postgresql
      encoding: unicode
      # For details on connection pooling, see rails configuration guide
      # http://guides.rubyonrails.org/configuring.html#database-pooling
      pool: 5
    
    development:
      <<: *default
      database: my_app_development
    
  4. rake db:migrate

Ruby相关问答推荐

当我在 Ruby 中围绕最后一个字符拆分时,如何拆分字符串?

Ruby - 给定一个嵌套数组的数组,如何仅比较每个嵌套数组的最后一个值来找到最大值?

Ruby符号前面的-是什么意思?

设计登录根路由rails 3

Rails 3 - 限制资源路径中的操作格式

如何在 Ruby 中生成一个包含 n 个唯一随机数的列表?

如何替换 ruby​​ 中模式的每个实例?

以编程方式获得完整的 Ruby 版本?

在 MacOS Sierra 上使用 RMagick 2.16 的 ImageMagick 7 找不到 MagickWand.h

使用 Bundler 时,为什么要关心 RVM 的 Gemset 功能?

类中的 Ruby 类(或模块中的模块)

将一个目录的内容复制到另一个目录

Vim 用 ruby​​ 语法高亮显示很慢

什么时候在 Ruby 中使用 Struct 比使用 Hash 更好?

RSpec:如何测试文件操作和文件内容

如何绘制 git repo 的代码行历史记录?

将 Ruby 哈希转换为 YAML

发现 Ruby 对象成员?

判断是否在 SASS 中定义了变量

如何将 270921sec 转换为天 + 小时 + 分钟 + 秒? (Ruby)