Puma not Starting Due to Spree Error
Hey Guys I am running Spree on Rails 5.1.2. I was trying to deploy a test spree app on my server using nginx, puma with the use of Capistrano. After the deployment I get this page with below error message.
We're sorry, but something went wrong. If you are the application owner check the logs for more information.
I have checked puma logs and found this error related to spree which I am unsure how to fix.
=== puma startup: 2017-07-15 23:30:57 -0400 === === puma startup: 2017-07-15 23:30:57 -0400 === ! Unable to load application: NoMethodError: undefined method `before_filter' for Spree::CheckoutController:Class Did you mean? before_action bundler: failed to load command: puma (/home/deploy/appname/shared/bundle/ruby/2.4.0/bin/puma)
Any help will be really appreciated.
Method `before_filter' got finally removed in Rails 5.1. Waiting spree_gateway gem to be updated and released.
@tathspts Can you share your Gemfile and Gemfile.lock? It would help me figure out what's causing your issue.
@symarys I had the exact same issue as his. Relevant Gemfile code snippet like this
gem 'rails', '~> 5.1.2'
gem 'spree', '~> 3.3.0.rc1'
gem 'spree_auth_devise', '~> 3.3.0.rc1'
gem 'spree_gateway', '~> 3.3.0.rc1'
After I changed Rails version to 5.0.4 and 3 Spree related gems to 3.2, the issue is gone.
@Austin-Qu @tathspts This issue for spree_gateway was solved on the master branch two weeks ago (https://github.com/spree/spree_gateway/commit/451d14f905164f929280ffac6263265c4b5b45f8). You should either install Spree 3.3 for Rails 5.1 or Spree 3.2 for Rails 5.0 (https://github.com/spree/spree#getting-started).
@Austin-Qu @tathspts spree_gateway 3.3.0.rc2 containing this fix was pushed to RubyGems, please run:
bundle update
Dear @damianlegawiec a similer error popped up while building a rails docker app. my Germfile spree setup is as follows:
gem spree_api, ~> 4.1
gem spree_core, ~> 4.1
gem spree_backend, ~> 4.1
gem spree_sample, ~> 4.1
gem spree_auth_devise, ~> 4.1
gem spree_gateway, ~> 3.8
I got the following error in the console:
Step 22/26 : RUN bundle exec rake assets:precompile
---> Running in 8b12257ddeb7
rake aborted!
NameError: uninitialized constant Spree::CheckoutController
Did you mean? Spree::CheckoutControllerDecorator
/usr/local/bundle/ruby/2.6.0/gems/spree_gateway-3.9.0/app/models/spree/checkout_controller_decorator.rb:19:in <main>
I set up the rails app with ruby '2.6.3' and dockerized it with ruby 2.6.3-slim-stretch
Thanks @Ifegwu - we're preparing a fix ASAP
@Ifegwu please update spree_gateway to 3.9.1 - it should fix your issue
Hi @damianlegawiec the issue still persists with spree_gateway to 3.9.1.
@damianlegawiec Can confirm still getting same error after updating to 3.9.1 in headless mode Gemfile:
gem spree_api, ~> 4.1
gem spree_core, ~> 4.1
gem spree_backend, ~> 4.1
gem spree_auth_devise, ~> 4.1
gem spree_gateway, ~> 3.9
NameError: uninitialized constant Spree::CheckoutController
spree_gateway-3.9.1/lib/spree_frontend/controllers/spree/checkout_controller_decorator.rb:19:in `'
Have added a PR that fixes this issue. https://github.com/spree/spree_gateway/pull/366
Thanks to @damianlegawiec and @dav-armour for your efforts in maintaining this wonderful gem.
I have updated the Gemfile with spree_gateway version 3.9.2, however, the error I got on the console is as follows:
rake aborted! NoMethodError: Cannot load database configuration:
undefined method gsub for nil:NilClass.
I have tried every available means to circumvent this error, but have not been able to. Any clue on what to do next?
Thank you.
@Ifegwu we would need a full backtrace to resolve your issue
Thank a lot @damianlegawiec Here is the console log when excluding the spree_gateway from the Gemfile.
/project/zoboo$ docker-compose up
Starting zoboo_postgres_1 ... done
Starting zoboo_zoboo_1 ... done
Attaching to zoboo_postgres_1, zoboo_zoboo_1
postgres_1 |
postgres_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_1 |
postgres_1 | 2020-11-10 13:58:34.201 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres_1 | 2020-11-10 13:58:34.201 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres_1 | 2020-11-10 13:58:34.268 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1 | 2020-11-10 13:58:34.462 UTC [20] LOG: database system was shut down at 2020-11-10 09:16:00 UTC
postgres_1 | 2020-11-10 13:58:34.675 UTC [1] LOG: database system is ready to accept connections
zoboo_1 | => Booting Puma
zoboo_1 | => Rails 6.0.3.4 application starting in development
zoboo_1 | => Run `rails server --help` for more startup options
zoboo_1 | /usr/local/bundle/ruby/2.6.0/gems/spree_core-4.1.11/app/models/spree/preferences/store.rb:9: warning: already initialized constant DB_EXCEPTIONS
zoboo_1 | /usr/local/bundle/ruby/2.6.0/gems/spree_core-4.1.11/app/models/spree/preferences/store.rb:9: warning: previous definition of DB_EXCEPTIONS was here
zoboo_1 | Puma starting in single mode...
zoboo_1 | * Version 4.3.6 (ruby 2.6.3-p62), codename: Mysterious Traveller
zoboo_1 | * Min threads: 5, max threads: 5
zoboo_1 | * Environment: development
zoboo_1 | * Listening on tcp://0.0.0.0:3000
zoboo_1 | Use Ctrl-C to stop
As you can see every thing works fine and I can access the admin. However, when include spree-gateway to the Gemfile, I get this following outputs:
Step 28/32 : RUN bundle exec rake assets:precompile
---> Running in e4e62403729b
rake aborted!
NoMethodError: Cannot load database configuration:
undefined method `gsub' for nil:NilClass
(erb):3:in `<main>'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/application/configuration.rb:228:in `database_configuration'
/usr/local/bundle/ruby/2.6.0/gems/activerecord-6.0.3.4/lib/active_record/railtie.rb:200:in `block (2 levels) in <class:Railtie>'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:43:in `block in on_load'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:42:in `each'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:42:in `on_load'
/usr/local/bundle/ruby/2.6.0/gems/activerecord-6.0.3.4/lib/active_record/railtie.rb:198:in `block in <class:Railtie>'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:32:in `instance_exec'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:32:in `run'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:61:in `block in run_initializers'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:60:in `run_initializers'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/application.rb:363:in `initialize!'
/zoboo/config/environment.rb:5:in `<main>'
/usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/usr/local/bundle/ruby/2.6.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/usr/local/bundle/ruby/2.6.0/gems/zeitwerk-2.4.1/lib/zeitwerk/kernel.rb:33:in `require'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:324:in `block in require'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:291:in `load_dependency'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:324:in `require'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/application.rb:339:in `require_environment!'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/application.rb:523:in `block in run_tasks_blocks'
/usr/local/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
/usr/local/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/usr/local/bundle/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/local/bundle/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/usr/local/bundle/bin/bundle:23:in `load'
/usr/local/bundle/bin/bundle:23:in `<main>'
Caused by:
NoMethodError: undefined method `gsub' for nil:NilClass
(erb):3:in `<main>'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/application/configuration.rb:228:in `database_configuration'
/usr/local/bundle/ruby/2.6.0/gems/activerecord-6.0.3.4/lib/active_record/railtie.rb:200:in `block (2 levels) in <class:Railtie>'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:43:in `block in on_load'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:42:in `each'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:42:in `on_load'
/usr/local/bundle/ruby/2.6.0/gems/activerecord-6.0.3.4/lib/active_record/railtie.rb:198:in `block in <class:Railtie>'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:32:in `instance_exec'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:32:in `run'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:61:in `block in run_initializers'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:60:in `run_initializers'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/application.rb:363:in `initialize!'
/zoboo/config/environment.rb:5:in `<main>'
/usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/usr/local/bundle/ruby/2.6.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/usr/local/bundle/ruby/2.6.0/gems/zeitwerk-2.4.1/lib/zeitwerk/kernel.rb:33:in `require'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:324:in `block in require'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:291:in `load_dependency'
/usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:324:in `require'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/application.rb:339:in `require_environment!'
/usr/local/bundle/ruby/2.6.0/gems/railties-6.0.3.4/lib/rails/application.rb:523:in `block in run_tasks_blocks'
/usr/local/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
/usr/local/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/usr/local/bundle/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/local/bundle/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/usr/local/bundle/bin/bundle:23:in `load'
/usr/local/bundle/bin/bundle:23:in `<main>'
Tasks: TOP => environment
(See full trace by running task with --trace)
ERROR: Service 'zoboo' failed to build: The command '/bin/sh -c bundle exec rake assets:precompile' returned a non-zero code: 1
The database.yml config file is as follows:
---
development:
url: <%= ENV['DATABASE_URL'].gsub('?', '_development?') %>
test:
url: <%= ENV['DATABASE_URL'].gsub('?', '_test?') %>
staging:
url: <%= ENV['DATABASE_URL'].gsub('?', '_staging?') %>
production:
url: <%= ENV['DATABASE_URL'].gsub('?', '_production?') %>
While a secret.yml file config which connects the database.yml file is as follows:
---
development: &default
secret_key_base: <%= Rails.application.credentials[Rails.env.to_sym][:SECRET_TOKEN] %>
test:
<<: *default
staging:
<<: *default
production:
<<: *default
@ifegwu The error looks like it is due to not having ENV['DATABASE_URL'] set in whatever environment you were using when it threw the error. Double check your environment variables is my recommendation
Thanks @dav-armour. I have been trying to resolve this environment variable issue, but have not been able to. I will check once again and revert.
Thanks @dav-armour and @damianlegawiec. Installing dotenv-rails gem resolved the issue.