Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.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数据库:安装rails中止!未定义的方法“[]';对于零:零I类';我正在使用Postgresql和rails 5_Ruby On Rails_Database_Postgresql_Ruby On Rails 5 - Fatal编程技术网

Ruby on rails rails数据库:安装rails中止!未定义的方法“[]';对于零:零I类';我正在使用Postgresql和rails 5

Ruby on rails rails数据库:安装rails中止!未定义的方法“[]';对于零:零I类';我正在使用Postgresql和rails 5,ruby-on-rails,database,postgresql,ruby-on-rails-5,Ruby On Rails,Database,Postgresql,Ruby On Rails 5,我试图运行railsdb:setup,但Postresql或配置有问题。我使用的是Rails 5.2.2、Linux机器、ruby 2.5.1p57 下面是我得到的错误: rails db:setup rails aborted! NoMethodError: undefined method `[]' for nil:NilClass /home/cabox/workspace/rails-5-boilerplate/config/environments/development.rb:69:

我试图运行
railsdb:setup
,但Postresql或配置有问题。我使用的是Rails 5.2.2、Linux机器、ruby 2.5.1p57

下面是我得到的错误:

rails db:setup
rails aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/home/cabox/workspace/rails-5-boilerplate/config/environments/development.rb:69:in `block in <main>'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/railtie.rb:216:in `instance_eval'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/railtie.rb:216:in `configure'
/home/cabox/workspace/rails-5-boilerplate/config/environments/development.rb:1:in `<main>'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/engine.rb:602:in `block (2 levels) in <class:Engine>'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/engine.rb:601:in `each'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/engine.rb:601:in `block in <class:Engine>'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `each'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `tsort_each_child'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
/home/cabox/workspace/rails-5-boilerplate/config/environment.rb:5:in `<main>'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/application.rb:337:in `require_environment!'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/command.rb:48:in `invoke'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<main>'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/home/cabox/workspace/rails-5-boilerplate/bin/rails:9:in `<top (required)>'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/home/cabox/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/home/cabox/workspace/rails-5-boilerplate/bin/spring:15:in `require'
/home/cabox/workspace/rails-5-boilerplate/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create => db:load_config => environment

Rails 5.2引入了。基本上,它允许我们创建一个加密的凭证文件,该文件可以使用
主.key
配置文件进行编辑,该文件用于解密
凭证.yml.enc
。在您的情况下,凭据文件不包含电子邮件标题,根据您的配置,该标题可能具有以下结构:

email:
  username: <String>
  password: <String>
  host: <String>
电子邮件:
用户名:
密码:
主持人:
您可以使用
EDITOR=vim-rails-credentials:edit
编辑凭证文件。如果您在编辑凭证文件时遇到问题,将有另一个讨论。以下链接可能有助于更好地理解凭据:


  • 你能分享一下
    config/environments/development
    文件吗?@AnujKhandelwal我刚刚添加了它。
    Rails.application.configure do
      # Settings specified here will take precedence over those in config/application.rb.
    
      # for gem `rack-livereload` https://github.com/onesupercoder/rack-livereload
      config.middleware.insert_after ActionDispatch::Static, Rack::LiveReload
    
      # In the development environment your application's code is reloaded on
      # every request. This slows down response time but is perfect for development
      # since you don't have to restart the web server when you make code changes.
      config.cache_classes = false
    
      # Do not eager load code on boot.
      config.eager_load = false
    
      # Show full error reports.
      config.consider_all_requests_local = true
    
      # Enable/disable caching. By default caching is disabled.
      # Run rails dev:cache to toggle caching.
      if Rails.root.join('tmp', 'caching-dev.txt').exist?
        config.action_controller.perform_caching = true
    
        config.cache_store = :memory_store
        config.public_file_server.headers = {
          'Cache-Control' => "public, max-age=#{2.days.to_i}"
        }
      else
        config.action_controller.perform_caching = false
    
        config.cache_store = :null_store
      end
    
      # Store uploaded files on the local file system (see config/storage.yml for options)
      config.active_storage.service = :local
    
      # Print deprecation notices to the Rails logger.
      config.active_support.deprecation = :log
    
      # Raise an error on page load if there are pending migrations.
      config.active_record.migration_error = :page_load
    
      # Highlight code that triggered database queries in logs.
      config.active_record.verbose_query_logs = true
    
      # Debug mode disables concatenation and preprocessing of assets.
      # This option may cause significant delays in view rendering with a large
      # number of complex assets.
      config.assets.debug = true
    
      # Suppress logger output for asset requests.
      config.assets.quiet = true
    
      # Raises error for missing translations
      # config.action_view.raise_on_missing_translations = true
    
      # Use an evented file watcher to asynchronously detect changes in source code,
      # routes, locales, etc. This feature depends on the listen gem.
      config.file_watcher = ActiveSupport::EventedFileUpdateChecker
    
      # Email config
      config.action_mailer.raise_delivery_errors = true
      config.action_mailer.perform_caching = false
      config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
      config.action_mailer.delivery_method = :smtp
      config.action_mailer.perform_deliveries = true
    
      # EMAIL SMTP
      config.action_mailer.smtp_settings = {
        user_name: Rails.application.credentials.email[:user_name],
        password: Rails.application.credentials.email[:password],
        address: Rails.application.credentials.email[:host],
        port: 587,
        enable_starttls_auto: true,
        format: :html,
        from: 'mail@rails-5-boilerplate.heroku.com'
      }
    end
    
    email:
      username: <String>
      password: <String>
      host: <String>