On Rails 6 app I had Rails.application.credentials in cap deploy.rb file. Now, when I try to deploy the new app with Rails 7 I'm getting
# bin/bundle exec cap production deploy --trace
NameError: uninitialized constant Rails
set :repo_url, Rails.application.credentials.git[:repo_url]
^^^^^
config/deploy.rb:5:in `<top (required)>'
/home/agasanov/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/capistrano-3.17.1/lib/capistrano/setup.rb:27:in `load'
/home/agasanov/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/capistrano-3.17.1/lib/capistrano/setup.rb:27:in `block (3 levels) in <top (required)>'
/home/agasanov/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/capistrano-3.17.1/lib/capistrano/configuration/variables.rb:32:in `untrusted!'
/home/agasanov/.rbenv/versions/3.1.3/lib/ruby/3.1.0/delegate.rb:87:in `method_missing'
^^^^^
Is this because autoloading from initializers have been removed from Rails 7?
Here is my deploy.rb
lock "~> 3.17.1"
set :application, "my app"
set :repo_url, Rails.application.credentials.git[:repo_url]
set :deploy_to, "/home/myapp/#{fetch :application}"
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
set :keep_releases, 5
Indeed, this is because autoloading works differently in Rails 7. You cannot autoload from the autoload paths, which are managed by the main autoloader. This applies to code in config/initializers as well as application or engines initializers.