Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails忽略config/database.yml_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails Rails忽略config/database.yml

Ruby on rails Rails忽略config/database.yml,ruby-on-rails,ruby,Ruby On Rails,Ruby,我使用Rails,但它不遵循config/database.yml中的设置 使用config/database.yml($database\u URL是我的Heroku应用程序数据库的URL) 在文件中: source 'https://rubygems.org' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https

我使用Rails,但它不遵循
config/database.yml
中的设置

使用
config/database.yml
$database\u URL
是我的Heroku应用程序数据库的URL)

在文件中:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

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

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '~> 2.13'
  gem 'selenium-webdriver'

  gem 'pry-rails'
  gem 'pry-doc'
  gem 'pry-byebug'
  gem 'pry-stack_explorer'

  # Use sqlite3 as the database for Active Record
  gem 'sqlite3'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'letter_opener'
  gem 'letter_opener_web'
end

group :production do
  gem 'pg', '~> 0.20'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'config'
gem 'bootstrap-sass'
gem 'kaminari'
gem 'jquery-rails'
gem 'gon'
gem 'faraday'
gem 'faraday_middleware'
gem 'devise'
gem 'devise-bootstrap-views'
gem 'data-confirm-modal'
源代码'https://rubygems.org'
git_源(:github)do | repo_名称|
repo_name=“#{repo_name}/#{repo_name}”除非repo_name.include?(“/”)
"https://github.com/#{repo_name}.git“
结束
#捆绑边缘Rails:gem'Rails',github'Rails/Rails'
gem'rails',“~>5.1.4”
#使用Puma作为应用程序服务器
宝石“彪马”,“大于3.7”
#将SCS用于样式表
gem'sass-rails',“~>5.0”
#使用Uglifier作为JavaScript资产的压缩器
gem'uglifier','>=1.3.0'
#看https://github.com/rails/execjs#readme 获取更多受支持的运行时
#宝石“therubyracer”,平台::ruby
#将CoffeeScript用于.coffee资产和视图
gem“咖啡轨”,“~>4.2”
#Turbolinks使web应用程序的导航速度更快。阅读更多:https://github.com/turbolinks/turbolinks
gem“涡轮链接”,“大于5”
#轻松构建JSON API。阅读更多:https://github.com/rails/jbuilder
gem'jbuilder',“~>2.5”
#使用Redis适配器在生产中运行操作电缆
#gem'redis',“~>3.0”
#使用ActiveModel具有\u安全\u密码
#gem'bcrypt',“~>3.1.7”
#使用Capistrano进行部署
#gem“capistrano rails”,集团::开发
小组:开发,:测试
#在代码中的任意位置调用“byebug”以停止执行并获得调试器控制台
gem'byebug',平台:[:mri,:mingw,:x64_mingw]
#增加了对Capybara系统测试和selenium驱动程序的支持
宝石“水豚”,“大于2.13”
gem“selenium webdriver”
宝石“撬轨”
宝石“撬动博士”
宝石“撬来撬去”
gem“pry-stack_explorer”
#使用sqlite3作为活动记录的数据库
gem'sqlite3'
结束
小组:发展怎么办
#在异常页面上或通过使用代码中的任意位置访问IRB控制台。
gem“web控制台”,“>=3.3.0”
gem'listen','>=3.0.5','<3.2'
#Spring通过让应用程序在后台运行来加速开发。阅读更多:https://github.com/rails/spring
宝石“春天”
gem‘SpringWatcherListen’,“~>2.0.0”
宝石“开封信”
创业板“信的开场白”
结束
小组:生产部
宝石'pg','~>0.20'
结束
#Windows不包括zoneinfo文件,因此捆绑tzinfo数据
gem'tzinfo data',平台:[:mingw,:mswin,:x64_mingw,:jruby]
gem'config'
gem‘引导式sass’
宝石“卡米纳里”
gem'jqueryrails'
宝石“gon”
宝石法拉第
“法拉第”宝石
宝石“设计”
gem“设计引导视图”
gem“数据确认模式”
我的ruby版本是v2.5.0,操作系统是macOS Sierra 10.12.6

为什么适配器设置为
postgresql
,而不考虑
config/database.yml
中的
sqlite3
? 如何正确使用配置


我考虑将开发环境迁移到虚拟机(以避免像这样麻烦的问题),但我担心,在虚拟机中,我也会遇到这样的错误。可以吗?

Rails使用的是环境变量中的连接详细信息,而不是配置文件。Rails在设置数据库时同时使用
ENV['DATABASE_URL']
config/DATABASE.yml
,在大多数情况下,环境变量具有优先级

看一看这两种配置数据库的方法是如何相互作用的

在您的情况下,最简单的解决方案可能是从开发机器中删除
数据库\u URL
变量。您不太可能需要将其设置在那里,如果您从开发中意外连接到生产数据库,则可能会导致问题

在指定开发数据库时,还可以使用
url:
键而不是
数据库:
键,因为该键的优先级高于环境变量。它看起来像:

development:
  <<: *default
  url: sqlite:db/development.sqlite3
开发:

Rails使用的是环境变量中的连接详细信息,而不是配置文件。Rails在设置数据库时同时使用
ENV['DATABASE_URL']
config/DATABASE.yml
,在大多数情况下,环境变量具有优先级

看一看这两种配置数据库的方法是如何相互作用的

在您的情况下,最简单的解决方案可能是从开发机器中删除
数据库\u URL
变量。您不太可能需要将其设置在那里,如果您从开发中意外连接到生产数据库,则可能会导致问题

在指定开发数据库时,还可以使用
url:
键而不是
数据库:
键,因为该键的优先级高于环境变量。它看起来像:

development:
  <<: *default
  url: sqlite:db/development.sqlite3
开发:

Sqlite通常不用于生产。您应该在本地使用Postgres,或者只在开发组中使用sqlite。非常确定你不能在Heroku上使用sqlite。是的,我同意Heroku-pg上没有sqlite。sqlite通常不会在生产中使用。您应该在本地使用Postgres,或者只在开发组中使用sqlite。非常确定你不能在Heroku上使用sqlite。是的,我同意Heroku-pg上没有sqlite。谢谢你的建议!很好,谢谢你的建议!很好。
development:
  <<: *default
  url: sqlite:db/development.sqlite3