use*_*293 31 ruby postgresql activerecord heroku ruby-on-rails-4
当我使用heroku打开我的网络应用程序工作正常,但当我使用rails(localhost)时,我遇到了这个错误:
ActiveRecord::AdapterNotSpecified database configuration does not specify adapter
Run Code Online (Sandbox Code Playgroud)
为什么是这样?
这是我的database.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
Run Code Online (Sandbox Code Playgroud)
这是我的宝石文件:
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]
Run Code Online (Sandbox Code Playgroud)
Uri*_*ssi 14
为了让您的应用程序在本地工作,您需要:
my_app_development
)将您更改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
Run Code Online (Sandbox Code Playgroud)跑 rake db:migrate
yek*_*kta 13
您没有显示导致此查询的命令,但如果您传递字符串而不是符号,则可能会发生这种情况.
例如:
irb(main):001:0> ActiveRecord::Base.establish_connection("#{Rails.env}")
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
Run Code Online (Sandbox Code Playgroud)
但是,如果你使用符号,它将起作用.
irb(main):001:0> ActiveRecord::Base.establish_connection("#{Rails.env}".to_sym)
=> #<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007f2f484a32a0 #....
Run Code Online (Sandbox Code Playgroud)
您的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
username: my_username
password: my_password
development:
<<: *default
database: "development_database_name"
test:
<<: *default
database: "test_database_name"
production:
<<: *default
database: "production_database_name"
Run Code Online (Sandbox Code Playgroud)
将development_database_name编辑为本地数据库名称.同时将my_username和my_password编辑为正确的db用户名和密码.
归档时间: |
|
查看次数: |
61132 次 |
最近记录: |