I can't run 'cap XXX deploy' to remote host - ruby-on-rails

I can ssh login to my AWS's host, But when I want to use Capistrano for deploying something to a remote host, it says
NoMethodError: undefined method `gsub' for nil:NilClass
ruby version:ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]
It's my error log trace:
cap demo deploy --trace
** Invoke demo (first_time)
** Execute demo
** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
NoMethodError: undefined method `gsub' for nil:NilClass
/Library/Ruby/Gems/2.3.0/gems/capistrano-3.11.0/lib/capistrano/defaults.rb:2:in `block in <top (required)>'
/Library/Ruby/Gems/2.3.0/gems/capistrano-3.11.0/lib/capistrano/configuration/validated_variables.rb:89:in `block in assert_valid_now'
/Library/Ruby/Gems/2.3.0/gems/capistrano-3.11.0/lib/capistrano/configuration/validated_variables.rb:88:in `each'
/Library/Ruby/Gems/2.3.0/gems/capistrano-3.11.0/lib/capistrano/configuration/validated_variables.rb:88:in `assert_valid_now'
/Library/Ruby/Gems/2.3.0/gems/capistrano-3.11.0/lib/capistrano/configuration/validated_variables.rb:44:in `set'
config/deploy.rb:1:in `<top (required)>'
/Library/Ruby/Gems/2.3.0/gems/capistrano-3.11.0/lib/capistrano/setup.rb:27:in `load'
/Library/Ruby/Gems/2.3.0/gems/capistrano-3.11.0/lib/capistrano/setup.rb:27:in `block (3 levels) in <top (required)>'
/Library/Ruby/Gems/2.3.0/gems/capistrano-3.11.0/lib/capistrano/configuration/variables.rb:32:in `untrusted!'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/delegate.rb:83:in `method_missing'
/Library/Ruby/Gems/2.3.0/gems/capistrano-3.11.0/lib/capistrano/setup.rb:26:in `block (2 levels) in <top (required)>'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Library/Ruby/Gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/Library/Ruby/Gems/2.3.0/gems/capistrano-3.11.0/lib/capistrano/application.rb:14:in `run'
/Library/Ruby/Gems/2.3.0/gems/capistrano-3.11.0/bin/cap:3:in `<top (required)>'
/usr/local/bin/cap:22:in `load'
/usr/local/bin/cap:22:in `<main>'
Tasks: TOP => demo
THX Have a good day.

As far as I can tell, from a few minutes of looking in source-code, this comes from the lack of :application setting in either config/deploy.rb or the environment specific deploy-config file.
We have, for example, just an excerpt of config:
set :application, 'myappname'
set :repo_url, 'git#github.com:org/app.git'
set :deploy_via, :remote_cache
# Default branch is :master
set :branch, :master
The error is thrown, from validate :application do |_key, value| in capistrano, which suggests that application is nil - Which it will be, if the value is unset (see config above).
Can you validate, that you have set :application in the config?

Related

Deploying Rails with Capistrano, undefined method upcase for nil

Deploying a Rails app to a new server, for the first time.
Running cap production deploy --trace gives me:
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
NoMethodError: undefined method `upcase' for nil:NilClass
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-1.14.0/lib/sshkit/configuration.rb:90:in `logger'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-1.14.0/lib/sshkit/configuration.rb:51:in `output_verbosity='
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/capistrano-3.9.0/lib/capistrano/configuration.rb:94:in `block in configure_backend'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sshkit-1.14.0/lib/sshkit.rb:11:in `configure'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/capistrano-3.9.0/lib/capistrano/configuration.rb:92:in `configure_backend'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/capistrano-3.9.0/lib/capistrano/setup.rb:32:in `block (2 levels) in <top (required)>'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/capistrano-3.9.0/lib/capistrano/application.rb:14:in `run'
/Users/dfaulken-af/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/capistrano-3.9.0/bin/cap:3:in `<top (required)>'
/Users/dfaulken-af/.rbenv/versions/2.4.1/bin/cap:22:in `load'
/Users/dfaulken-af/.rbenv/versions/2.4.1/bin/cap:22:in `<main>'
Tasks: TOP => production
Which seems entirely confined to gem code. Before I open an issue with them (sshkit?), has anyone seen this before?
I use Net::SSH::Config to get the SSH user from my SSH config file. I know that those settings are correct, as I'm able to use them to log into the server.
remote_user = Net::SSH::Config.for('50.198.83.200')[:user] || ENV['USER']
server '50.198.83.200', user: remote_user, roles: %w(app db web)
But I've tried setting the remote user with USER=the_user_name cap, etc. and still get the same error.
My log_level line was incompletely written as
set :log_level
With no second argument.

Redmine receiving emails from imap

I have installed Redmine 2.6.1-stable, it works using apache2 and passenger.
I'm trying to receive emails using imap with this two rakes:
this one:
rake -f /opt/redmine-2.6.1/Rakefile --silent redmine:email:receive_imap RAILS_ENV="production" host=smtp.yandex.ru port=465 username=mail#yandex.ru password=pwd ssl=true project=desk folder=INBOX move_on_success=processed move_on_failure=failed no_permission_check=1 unknown_user=accept
And this one:
bundle exec rake redmine:email:receive_imap host='smtp.yandex.ru' username='mail#yandex.ru' password='pwd' port=465 ssl=true starttls=true allow_override=type,project project=desk
And this is log:
** Invoke redmine:email:receive_imap (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute redmine:email:receive_imap
rake aborted!
EOFError: end of file reached
/home/admin/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/imap.rb:1150:in `get_tagged_response'
/home/admin/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/imap.rb:1210:in `block in send_command'
/home/admin/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/admin/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/imap.rb:1192:in `send_command'
/home/admin/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/imap.rb:435:in `login'
/opt/redmine-2.6.1/lib/redmine/imap.rb:30:in `check'
/opt/redmine-2.6.1/lib/tasks/email.rake:128:in `block (4 levels) in <top (required)>'
/opt/redmine-2.6.1/app/models/mailer.rb:367:in `with_synched_deliveries'
/opt/redmine-2.6.1/lib/tasks/email.rake:127:in `block (3 levels) in <top (required)>'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/task.rb:240:in `call'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/admin/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/bin/rake:23:in `load'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/bin/rake:23:in `<main>'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/bin/ruby_executable_hooks:15:in `eval'
/home/admin/.rvm/gems/ruby-2.1.5#rails3/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => redmine:email:receive_imap
I can't understand what's going on.. Why it does not work properly?
Log /opt/redmine-2.6.1/logs/production.log is empty about this operation.
I recently solved my similar problem with enabling debug on IMAP, so I could see what's happened. To do that;
vim /var/www/redmine/lib/redmine/imap.rb
and after require 'net/imap' add this line:
Net::IMAP.debug = true
It usually relates to the login credentials/method.
You are trying to receive IMAP email from an SMTP server. These are completely different protocols.
Likely you want server imap.yandex.ru, Port 993, with SSL (not starttls).
Settings for IMAP appear to be available at https://yandex.com/support/mail/mail-clients.xml

state_machine draw throws uninitialized constant error

On a Rails 3.2 application
Gemfile:
gem "state_machine", "~> 1.1.2"
gem 'ruby-graphviz', :require => 'graphviz'
I installed and use with success the state_machine gem, only when I try to draw the state graph
rake state_machine:draw CLASS=Entity
it throws me this error:
** Invoke state_machine:draw (first_time)
** Execute state_machine:draw
** Invoke environment (first_time)
** Execute environment
rake aborted!
uninitialized constant StateMachine::Machine::Constants
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:1898:in `draw'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:481:in `block (2 levels) in draw'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:480:in `each_value'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:480:in `block in draw'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:472:in `each'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:472:in `draw'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/tasks/state_machine.rb:27:in `block (2 levels) in <top (required)>'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/Users/joel/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/bin/rake:19:in `load'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/bin/rake:19:in `<main>'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/bin/ruby_noexec_wrapper:14:in `eval'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => state_machine:draw
Any leads on how to troubleshoot this one?
Dirty but works:
unless defined? StateMachine::Machine::Constants::RGV_VERSION
warn "StateMachine::Machine::Constants overriden in #{__FILE__}"
class StateMachine::Machine::Constants
RGV_VERSION = /^[ ]*ruby-graphviz \(([0-9.]+)\)/.match(`cat #{Rails.root.join 'Gemfile.lock'}`)[1]
end
end
To elaborate on tsiruu answer: in case you are using rails, just take his code and put it in an initializer
unless defined? StateMachine::Machine::Constants::RGV_VERSION
warn "StateMachine::Machine::Constants overriden in #{__FILE__}"
class StateMachine::Machine::Constants
RGV_VERSION = /^[ ]*ruby-graphviz \(([0-9.]+)\)/.match(`cat #{Rails.root.join 'Gemfile.lock'}`)[1]
end
end

Rake Task to Restart Heroku Server

I'm trying to create a rake task that restarts my heroku servier. I've found this post, which has helped immensely: http://railspikes.com/2010/2/13/rake-task-for-deploying-to-heroku.
I've cobbled together this rake task, but it's giving me an error. The rake abouts and I get the message:
uninitialized constant Heroku::Command::BaseWithApp.
This is my method.
desc 'restarts the server'
task restart_server: :environment do
require 'heroku'
require 'heroku/command'
user, pass = File.read(File.expand_path("~/.heroku/credentials.txt")).split("\n")
heroku = Heroku::Client.new(user, pass)
cmd = Heroku::Command::BaseWithApp.new([])
remotes = cmd.git_remotes(File.dirname(__FILE__) + "/../..")
remote, app = remotes.detect {|key, value| value == (ENV['APP'])}# || cmd.app)}
if remote.nil?
raise "Could not find a git remote for the '#{ENV['APP']}' app"
end
heroku.restart(ENV['APP'])
end
I'm not sure why it's rejecting Heroku::Command. The app is already live on Heroku, so I know it's Heroku compliant.
Any advice?
EDIT: Here's my stack trace.
** Invoke restart_server (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute restart_server
rake aborted!
uninitialized constant Heroku::Command::BaseWithApp
/Users/bendowney/Sites/ProblemChildApp/lib/tasks/scheduler.rake:51:in `block in <top (required)>'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/bendowney/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `load'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `<main>'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#ProblemChildApp/bin/ruby_noexec_wrapper:14:in `eval'
/Users/bendowney/.rvm/gems/ruby-1.9.3-p194#ProblemChildApp/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => restart_server

rake assets:precompile attempting to connect to database

I'm attempting to debug why my application is attempting to connect to my database when I run rake assets:precompile --trace.
I'm probably missing something in the stack trace...anyone see the pertinent line?
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in ActionController::Base instead. (called from <top (required)> at /Users/Kyle/Desktop/skateparks-web/config/application.rb:4)
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in ActionController::Base instead. (called from <top (required)> at /Users/Kyle/Desktop/skateparks-web/config/application.rb:4)
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
rake aborted!
FATAL: database "skateparks_production" does not exist
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `initialize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `new'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `connect'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:316:in `initialize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:27:in `new'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:27:in `postgresql_connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:277:in `new_connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:287:in `checkout_new_connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:235:in `block (2 levels) in checkout'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `loop'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `block in checkout'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `checkout'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/model_schema.rb:308:in `clear_cache!'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/railtie.rb:91:in `block (2 levels) in <class:Railtie>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:418:in `_run__2041913228368879189__prepare__1991931652306887621__callbacks'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/application/finisher.rb:48:in `block in <module:Finisher>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `instance_exec'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `run'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `run_initializers'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/application.rb:136:in `initialize!'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/Kyle/Desktop/skateparks-web/config/environment.rb:5:in `<top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `block in require'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/application.rb:103:in `require_environment!'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/sprockets/assets.rake:89:in `block (2 levels) in <top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:174:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/sprockets/assets.rake:56:in `block (3 levels) in <top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/bin/rake:19:in `load'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/bin/rake:19:in `<main>'
Tasks: TOP => environment
rake aborted!
Command failed with status (1): [/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/bi...]
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils.rb:45:in `call'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils.rb:45:in `sh'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `sh'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils.rb:78:in `ruby'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `ruby'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/sprockets/assets.rake:9:in `ruby_rake_task'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/sprockets/assets.rake:17:in `invoke_or_reboot_rake_task'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/sprockets/assets.rake:25:in `block (2 levels) in <top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/bin/rake:19:in `load'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/bin/rake:19:in `<main>'
Tasks: TOP => assets:precompile
rake assets:precompile initializes your app by default, which includes connection to the database.
Inside config/application.rb you can add this, but see the link below for warnings about it:
config.assets.initialize_on_precompile = false
Rails Guide on Precompiling Assets
I had that same problem. After updating Sprockets to version 3, whenever I tried to precompile the assets locally (development), however using the settings of the production environment, I had this error:
rake aborted!
Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
Because in my local (development) I use MySQL and in the server (production), I use Postgres.
The answer marked as resolved does not work for me, because config.assets.initialize_on_precompile is not available in Rails 4.2.1.
To solve, I followed 3 simple steps:
In your Gemfile, add: gem "activerecord-nulldb-adapter"
In database.yml, change the adapter as follow:
production:
adapter: <%= ENV['DB_ADAPTER'] ||= 'postgresql' %>
To compile your production assets locally. run in your terminal
DB_ADAPTER=nulldb RAILS_ENV=production rake assets:precompile
This solutions solved to me and I sawyed here.
Newer versions of Rails do not load the database during asset precompile. However, initializers will often cause it to load. This can be frustrating to debug, because the error omits the stack trace.
./bin/rails assets:precompile
(in ~/src/nautilus)
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: database "your_app_development" does not exist
bundler: failed to load command: rake (~/src/your_app/vendor/bundle/ruby/2.6.0/bin/rake)
NoMethodError: undefined method `reject' for nil:NilClass
The less than helpful error.
So, how do we figure out where the problem is?
Move all the initializers out of config/initializers then run ./bin/rails assets:precompile.
If it works, great, you know the problem is in one of those files.
Move them back one by one till you find the offending file(s).
Now that the problem was found, how do we fix it?
Then when I find an initialilzer that has a problem I wrap it with the following check:
unless ARGV.include? "assets:precompile"
# ...
end
I prefer this over the nulldb because it reduces the number of dependencies I have to maintain in the app.
If it makes sense in your situation, you can choose against which environment assets:precompile should work, with the following command:
rake assets:precompile:all RAILS_ENV=development RAILS_GROUPS=assets
This make sense for my deployment because usually:
I make rake to generates assets on my development machine (because the memory of my vps is somehow limited)
I zip all the application with the assets generated in public/assets
I transfer the zip to the vps ans unzip the package there
Hope it helps.
Check your configuration files (in all environments). If for example
rake assets:precompile
works in development, but you are having issues in production
RAILS_ENV=production bundle exec rake assets:precompile
then you most likely have a reference to active record in your /config/environments/production.rb
config.active_record.dump_schema_after_migration = false
In order to avoid that altogether if you are planning on not taking advantage of active record or employing a NoSQL such as mongo, you may wish to initialize your new app as follows:
rails new myApp --skip-active-record
which is equivalent to -O (capital O) as far as I am concerned.
Maybe this won't work for all cases but I was able to avoid Rails attempting to connect to the database on the rake assets:* tasks by surrounding the code in some places with the snippet below on the /config/routes.rb:
unless defined?(::Rake::SprocketsTask)
devise_for ...
#...
end
devise_scope ...
#...
end
end
Sometimes code which depends on external services or environment variables will get loaded because of code on the initializer files which are not required for assets to be precompiled.
I've recently faced a similar issue and the responses above didn't work for me. I've found the file on config/initializers/ that was causing the issue and wrapped it with the following code:
unless defined?(::Rake::SprocketsTask)
#...
end
The snippet above will skip the code within it when running rake assets:precompile or others like rake assets:clean as well.
Hopefully this will help others in the future!

Resources