rails db: установка rails отменена!undefined метод `[] 'для nil: NilClass Я использую Postgresql и rails 5 - PullRequest
0 голосов
/ 03 июля 2019

Я пытаюсь запустить rails db: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

Вот файл database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: postgres
  password: mypassword

development:
  <<: *default
  database: rails-5-boilerplate_development

Вот файл /environments/development.rb:

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

1 Ответ

1 голос
/ 03 июля 2019

В Rails 5.2 введена концепция учетных данных .По сути, это позволяет нам создавать зашифрованный файл учетных данных, который можно редактировать с помощью файла конфигурации master.key, который используется для расшифровки credentials.yml.enc.В вашем случае файл учетных данных не содержит заголовок электронной почты, который, вероятно, будет иметь следующую структуру в зависимости от вашей конфигурации:

email:
  username: <String>
  password: <String>
  host: <String>

Вы можете редактировать файл учетных данных, используя EDITOR=vim rails credentials:edit.Если у вас есть проблемы с редактированием файла учетных данных, в этом вопросе есть еще одно обсуждение для того же .Следующие ссылки могут помочь лучше понять учетные данные:

  1. Зашифрованные учетные данные в Rails 5.2
  2. Учетные данные в Rails 5.2
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...