in `decode64': undefined method `unpack1' for nil:NilClass (NoMethodError) - ruby-on-rails

After deploying a new rails app to Heroku I'm getting a NoMethodError. Everything works fine locally. I'm unsure how to and where to add the method.
I'm new to ruby (coding in general) and it seems to be in the ruby-config and not this specific app, but I didn't have any problems with deploying other apps to Heroku so I wonder how the config could have changed.
I've added Postgres and Redis to Heroku and am using ruby 2.6.3 and Rails 6.0.0.rc1
Error message:
/app/vendor/ruby-2.6.3/lib/ruby/2.6.0/base64.rb:59:in `decode64': undefined method `unpack1' for nil:NilClass (NoMethodError)
2019-07-25T08:43:02.237469+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:37:in `<class:ConnectedAccount>'
2019-07-25T08:43:02.237508+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:31:in `<main>'
2019-07-25T08:43:02.237532+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
2019-07-25T08:43:02.237554+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
2019-07-25T08:43:02.237576+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
2019-07-25T08:43:02.237614+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
2019-07-25T08:43:02.237651+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2019-07-25T08:43:02.237674+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.6/lib/zeitwerk/kernel.rb:16:in `require'
2019-07-25T08:43:02.237696+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `block in require'
2019-07-25T08:43:02.237720+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:268:in `load_dependency'

The error happens if you call Base64.decode64(nil). The method however is strictly expecting a String object here.
You are likely calling the method with some variable that is usually supposed to be a String but is currently nil for some reason. Check your full stack trace and the related data to fix passed data to be a String.

You are likely missing the RAILS_MASTER_KEY in your environment.
From your stack trace, the error is generated at /app/app/models/user/connected_account.rb:37:
attr_encrypted :access_token, key: Base64.decode64(Rails.application.credentials.access_token_encryption_key)
For your production environment, you'll find the key by running:
cat config/credentials/production.key

Since it appears this is for Jumpstart users, here's the relevant solution.

Related

undefined method 'load_defaults' with Rails Generate

I'm really new to Ruby and its Rails framework and I was following a tutorial when I ran into some issues using the rails generate command. I tried using rails generate scaffold and rails generate controller but it didn't work. The full trace is this:
/usr/lib/ruby/vendor_ruby/rails/railtie/configuration.rb:95:in `method_missing': undefined method `load_defaults' for #<Rails::Application::Configuration:0x000055cdba53c180> (NoMethodError)
from /home/eric/Projects/blog/config/application.rb:12:in `<class:Application>'
from /home/eric/Projects/blog/config/application.rb:10:in `<module:Blog>'
from /home/eric/Projects/blog/config/application.rb:9:in `<top (required)>'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `require'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from -e:1:in `<main>'
I think that the main issue is that I'm missing the 'load_defaults' method, but I couldn't find anything on how to resolve the issue. For context, I'm doing this all on a completely new rails project on Ubuntu - the only things I've done so far are rails new and bundle install.
Somewhat curiously, this issue is only popping up on new rails projects that I've created. I tried using rails generate commands on a project I had earlier and it worked. I couldn't figure out what was different between the projects though.
Any suggestions would be greatly appreciated!

Method_missing error when running "rails server"

I'm just starting a new rails app but it doesn't let me start the server, after typing 'rails s' the console just pukes me out this;
/Users/user/.rvm/gems/ruby-2.4.1/gems/railties-4.2.9/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `load_defaults' for #<Rails::Application::Configuration:0x007fa393f7db20> (NoMethodError)
from /Users/user/Desktop/MiProyecto/Portafolio/config/application.rb:12:in `<class:Application>'
from /Users/user/Desktop/MiProyecto/Portafolio/config/application.rb:10:in `<module:Portafolio>'
from /Users/user/Desktop/MiProyecto/Portafolio/config/application.rb:9:in `<top (required)>'
from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:78:in `require'
from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:78:in `block in server'
from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:75:in `server'
from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-4.2.9/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:9:in `require'
from bin/rails:9:in `<main>'
Any thoughts?
Thanks in advance.
ps: I already ran bundle install and it went out perfectly.
Check in which Rails version you started your application. If by any chance you changed it, upgrading or downgrading it, then, just to be sure, try removing the Gemfile.lock file, adding the "original" Rails version and bundling again.
I reproduced the 'method_missing': undefined method 'load_defaults' error firstly creating a blank Rails application using the 5.1.3 version, and then changing it to the 5.0.1, removing the Gemfile.lock and running bundle.

Cannot run any commands on my heroku app (migrate, console, etc)

I am running rails 4.0.4 with ruby 2.1.1. app location: https://github.com/ravjohal/dozmia
When I try to run commands on heroku, for instance:
ravjohal$ heroku run rake db:migrate
I get the following error:
Running `rake db:migrate` attached to terminal... up, run.2545
rake aborted!
NoMethodError: undefined method `dump_schema_after_migration=' for ActiveRecord::Base:Class
/app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/railtie.rb:166:in `block (3 levels) in <class:Railtie>'...../app/config/environment.rb:5:in `<top (required)>'....
here is part of the heroku logs:
/app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `dump_schema_after_migration=' for #<Class:0x007fa6e13d76d0> (NoMethodError)
2014-03-27T18:30:55.729964+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
2014-03-27T18:30:55.729964+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
2014-03-27T18:30:55.729964+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:44:in `each'
2014-03-27T18:30:55.730401+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/engine.rb:464:in `each'
2014-03-27T18:30:55.730191+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'
2014-03-27T18:30:55.730191+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
2014-03-27T18:30:55.729964+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
2014-03-27T18:30:55.729964+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/railtie.rb:165:in `block (2 levels) in <class:Railtie>'
2014-03-27T18:30:55.729964+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
2014-03-27T18:30:55.729964+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/railtie.rb:165:in `each'
2014-03-27T18:30:55.730191+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `b
lock in require'
2014-03-27T18:30:55.730191+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/base.rb:22:in `<top (required)>'
2014-03-27T18:30:55.730191+00:00 app[web.1]: from /app/app/models/playlist.rb:1:in `<top (required)>'
I had deployed my app using 4.1.0rc1 Rails (worked fine) and then changed the Gemfile to use 4.0.4 instead. I also changed my local development database to pg instead of sqllite3. Those are the only two changes I have made and only after those changes did the issue appear on heroku. App works great on localhost.
EDIT: I also want to add that I changed the app name locally (not sure if that would matter though).
So after trying many things, and hitting myself on the head for NOT trying something obvious...I removed the following line from environments/production.rb file:
config.active_record.dump_schema_after_migration = false
It worked fine on heroku thereafter.
The config dump_schema_after_migration didn't exist in Rails 4.0.4 .
You got the error because you deployed initially with Rails v4.1.0rc1 and switched over to v4.0.4 later. What really happened is that when you generated your app with rails 4.1.0rc, the generator put the config dump_schema_after_migration into your config/environments/production.rb and Rails 4.1.0rc1's code has this to support this config :
mattr_accessor :dump_schema_after_migration
Hence everything works fine in v4.1.0rc1. But when you moved back to v4.0.4, the config is still there in config/environments/production.rb , but the Rails code no longer knows how to read this config. To solve this, either stick with Rails 4.1.0rc1 code, or remove the config from config/environments/production.rb when running on Rails 4.0.4.
Btw, I added dump_schema_after_migration config to Rails code.
I don't have an answer, but a reason why the issue will be happening
When using a beta version of a product (Rails), you'll get a lot of new (relatively untested) functionality. This will work, but may cause issues with earlier versions of the software, as new generally means more functionality etc
If you're starting with Rails, I would recommend removing the Rails 4.1.0 gem from your system: gem uninstall rails, and then installing Rails 4.0.4 again - gem install rails
It's going to be an issue with Rails 4.1.0, but I'd need to experiment a little

Using rails console error

I have Produtor model on my app and I'm trying to debug it with rails console..
but when I try to use rails console inside my app directory I get this error
D:\ruby\app>rails console
Loading development environment (Rails 3.2.9)
irb(main):001:0> Produtors.all
NameError: uninitialized constant Produtors
from (irb):1
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
what is the problem?
You need to use the name of the model, Produtor instead. The extra s is what is throwing you off. Try Produtor.all instead.

What’s wrong with my local Rails environment?

There is a Rails application I started a full year ago. It’s a Rails 2.3 app.
Now, someone else has made remote changes (it’s on Github, sorry, but it’s private). And I have done
sudo gem update
that is, updated all my gems, including Rails (to 3).
Realizing this, I have done
rake:freeze:edge RELEASE=2.3.8
or whatever to make this release use that version of rails, hoping this was the solution.
however, no such luck so far.
I get errors trying to start the server, AND trying to run script/console (though it’s more successful).
Note that this exact application works just fine on EngineYard.
Server:
$ script/server
=> Booting Mongrel
=> Rails 2.3.8 application starting on http://0.0.0.0:3000
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load': syntax error on line 45, col 3: `' (ArgumentError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load'
from /Users/ajh/Sites/PROJECT_NAME/config/../vendor/rails/railties/lib/initializer.rb:902:in `database_configuration'
from /Users/ajh/Sites/PROJECT_NAME/config/../vendor/rails/railties/lib/initializer.rb:437:in `initialize_database'
from /Users/ajh/Sites/PROJECT_NAME/config/../vendor/rails/railties/lib/initializer.rb:141:in `process'
from /Users/ajh/Sites/PROJECT_NAME/config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
from /Users/ajh/Sites/PROJECT_NAME/config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
from /Users/ajh/Sites/PROJECT_NAME/config/environment.rb:11
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/railties/lib/commands/server.rb:84
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:3
Console:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in load':ArgumentError: syntax error on line 45, col 3:rai'
And when, in console, I try to use a defined model:
#mm = MyModel.find(:all)
NameError: uninitialized constant MyModel
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:443:in load_missing_constant'
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:80:inconst_missing'
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:92:in `const_missing'
from (irb):1
I just had this error, and the problem turned out to be that I'd used a tab instead of a double-space in the database.yml file. Thought I'd mention it, in case others have the same trouble.
My database.yml had a stray end keyword. Cleaning up that file solved my problems. Thanks to Garrett for pointing me in the right direction!

Resources