I have been updating several Rails Apps from Rails 3.2.5 to Rails 7. After having all of them migrated and deployed, one App suddenly refuses to start its web server (puma) in development.
I am able to get its rails server
to run in development once I delete the production database details from database.yml or change its production database credentials from
(1)
database: <%= Rails.application.credentials.database[:name-database] %>
username: <%= Rails.application.credentials.database[:username-database] %>
password: <%= Rails.application.credentials.database[:password-database] %>
to
(2)
database: <%= Rails.application.credentials[:name-database] %>
username: <%= Rails.application.credentials[:username-database] %>
password: <%= Rails.application.credentials[:password-database] %>
In all other Rails Apps the first option is working. The only difference between the rails.application.credentials of the apps, which are starting in dev mode and the app which is not starting, is, that the one, which is not starting only has secret_key_base and database "scopes" in production.yml.enc
secret_key_base: very_long_string
database:
name-database: a
username-database: b
password-database: c
whereas in the apps, which are running I have at least another "scope":
secret_key_base: very_long_string
something:
x: "x"
y: "y"
z: "z"
database:
name-database: a
username-database: b
password-database: c
Does anyone know what is going on? Thank you in advance. It is quite strange, because I was sure it worked before.
CodePudding user response:
I found out, that when I change the syntax to:
production:
database: <%= Rails.application.credentials.name-database %>
username: <%= Rails.application.credentials.username-database %>
password: <%= Rails.application.credentials.password-database %>
rails s
starts in development.
After some further research I found out that you cannot specify your credentials only in production.
rails credentials:edit --environment production
In case you scope your credentials for one environment you need to scope all environments. That is written nowhere. Again: You have to create credential files for all environments:
rails credentials:edit --environment development
rails credentials:edit --environment test
rails credentials:edit --environment production
In my case and in the applications, where I encountered problems, I used credentials only in production and relied on environment variables for development and test. For this reason I had only the production credentials for deployment. After creating credentials for all environments, even if I do not use them afterwards, the app starts in dev and production.