Я использую Rails 5 и получаю доступ к своим учетным данным с помощью RAILS_ENV=production EDITOR=vim rails credentials:edit
. Однако, когда я запускаю rails c -e production
, я получаю эту ошибку:
/usr/local/rvm/gems/ruby-2.5.8/gems/railties-5.2.4/lib/rails/application/configuration.rb:185:in `database_configuration': Cannot load database configuration:
Could not load database configuration. No such file - ["config/database.yml"] (RuntimeError)
from /usr/local/rvm/gems/ruby-2.5.8/gems/activerecord-5.2.4/lib/active_record/railtie.rb:133:in `block (2 levels) in <class:Railtie>'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:51:in `each'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activerecord-5.2.4/lib/active_record/base.rb:328:in `<module:ActiveRecord>'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activerecord-5.2.4/lib/active_record/base.rb:27:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.5.8/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
from /usr/local/rvm/gems/ruby-2.5.8/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
Почему этот файл требуется? Как мне это игнорировать? Просто для удовольствия я создал файл config/database.yml
, который выглядит так:
default: &default
adapter: postgresql
encoding: unicode
pool: 200
port: 25060
production:
<<: *default
host: <%= Rails.application.credentials.production[:host] %>
username: <%= Rails.application.credentials.production[:username] %>
password: <%= Rails.application.credentials.production[:password] %>
database: <%= Rails.application.credentials.production[:database] %>
development:
<<: *default
host: <%= Rails.application.credentials.development[:host] %>
username: <%= Rails.application.credentials.development[:username] %>
password: <%= Rails.application.credentials.development[:password] %>
database: <%= Rails.application.credentials.development[:database] %>
Однако, когда я запускаю rails c -e production
, я все равно получаю эту ошибку:
(erb):14:in `<main>': Cannot load database configuration:
undefined method `[]' for nil:NilClass (NoMethodError)
from /usr/local/rvm/rubies/ruby-2.5.8/lib/ruby/2.5.0/erb.rb:876:in `eval'
from /usr/local/rvm/rubies/ruby-2.5.8/lib/ruby/2.5.0/erb.rb:876:in `result'
from /usr/local/rvm/gems/ruby-2.5.8/gems/railties-5.2.4/lib/rails/application/configuration.rb:172:in `database_configuration'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activerecord-5.2.4/lib/active_record/railtie.rb:133:in `block (2 levels) in <class:Railtie>'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
from /usr/local/rvm/gems/ruby-2.5.8/gems/activesupport-5.2.4/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
Я могу получить доступ к экземпляру разработки, но не к производству. Не совсем понимаю, зачем нужен этот файл, если Rails 5 якобы от него уходит. Любая помощь будет принята с благодарностью.