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
Related
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.
I have just cloned a github repo https://github.com/maxitron93/p2pcollective.com, as i was exploring this awesome p2p lending app i encountered an error
NoMethodError: undefined method `alias_method_chain' for ActiveRecord::ConnectionAdapters::PostgreSQLColumn:Class
both when migrationg db or raunning server. I'm using the cloud9 ide to avoid my pc environment.
Running through a couple of solution posts, i updated my gem store with device and erubis but still returned back to that 'alias_method_chain' error.
Here's a snippet of my logs:
rake db:migrate
rake aborted!
NoMethodError: undefined method `alias_method_chain' for ActiveRecord::ConnectionAdapters::PostgreSQLColumn:Class
Did you mean? alias_method
/usr/local/rvm/gems/ruby-2.3.4/gems/activerecord-postgres-hstore-0.7.8/lib/activerecord-postgres-hstore/activerecord.rb:80:in `<class:PostgreSQLColumn>'
/usr/local/rvm/gems/ruby-2.3.4/gems/activerecord-postgres-hstore-0.7.8/lib/activerecord-postgres-hstore/activerecord.rb:74:in `<module:ConnectionAdapters>'
/usr/local/rvm/gems/ruby-2.3.4/gems/activerecord-postgres-hstore-0.7.8/lib/activerecord-postgres-hstore/activerecord.rb:70:in `<module:ActiveRecord>'
/usr/local/rvm/gems/ruby-2.3.4/gems/activerecord-postgres-hstore-0.7.8/lib/activerecord-postgres-hstore/activerecord.rb:2:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:256:in `block in load_dependency'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:662:in `new_constants_in'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:256:in `load_dependency'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
/usr/local/rvm/gems/ruby-2.3.4/gems/activerecord-postgres-hstore-0.7.8/lib/activerecord-postgres-hstore/railties.rb:18:in `block (2 levels) in <class:Hstore>'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:69:in `instance_eval'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
I expect my rails server to run smoothly from here.
alias_method_chain was deprecated and removed in Rails 5, but existed prior to that. It looks like a dependency (possibly pg) that has been installed is incompatible. You may be able to resolve the issue with bundle update pg, and if not, a broader bundle update should do the trick.
EDIT:
This is what I get for internet'ing before coffee. The gem responsible is in your stacktrace: activerecord-postgres-hstore, which isn't in the project you linked to, which suggests you've made other changes. You don't need that gem for Rails 4+. More info here
In my case, I had gem 'foreigner package from Gemfile
gem uninstall foreigner
bundle install
rails db:migrate
I hope it will be helpfull
I am currently attempting to upgrade a Rails 3.2 app to Rails 4. I updated my Gemfile by referencing the correct version of Rails:
gem 'rails', '~>4.0.0'
as well as removing the assets header, per here.
Next, I attempted to run rake rails:update. It gave me this error:
rake aborted!
NameError: uninitialized constant ActiveModel::ForbiddenAttributesProtection
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:6:in `<module:AttributeAssignment>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:3:in `<module:ActiveRecord>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:2:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:300:in `<class:Base>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:281:in `<module:ActiveRecord>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:22:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/railtie.rb:38:in `block in <class:Railtie>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `instance_exec'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `block in run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/application.rb:253:in `block in run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine/railties.rb:17:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine/railties.rb:17:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/application.rb:253:in `run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine.rb:446:in `load_tasks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
/vagrant/Rakefile:7:in `<top (required)>'
(See full trace by running task with --trace)
What is causing this error?
The only place I could find this error online was this GitHub issue.
I searched for ActiveModel::ForbiddenAttributesProtection on that page, and found it here.
As I was reading that comment and following, I found this one, which said:
Rails 3.2 apps can just add strong_parameter gem AFAIK and it would work out of the box.
Looking at my Gemfile again I realized what the problem was. It contained this line:
gem 'strong_parameters'
The problem is that the strong_parameters gem duplicates the Rails 4 way of doing things, allowing newer, better code to be used in Rails 3.2. Thus, it conflicts with the built-in functionality in Rails 4.
I removed that line from my Gemfile, and after running bundle, the rake command worked.
Edit: After restarting unicorn, I was getting a similar error in the log. I deleted config/initializers/strong_parameters.rb, but that didn't seem to help. However, after rebooting my VM, it was working properly.
I just installed carrierwave and have set my rails 4 app up to store images on Amazon s3 through fog. The app was working and deploying to Heroku with Carrierwave (but images were getting purged with dyno). After some initial issues I got it working on my localhost (as far as I could tell).
Now I am having trouble pushing the new version to Heroku. I have reset the DATABASE. Precompiled the assets and now trying to migrate the database. Below is the error I'm getting.
Running `rake db:migrate` attached to terminal... up, run.6517
rake aborted!
uninitialized constant Sprockets::Helpers
/app/app/uploaders/image_uploader.rb:12:in `<class:ImageUploader>'
/app/app/uploaders/image_uploader.rb:4:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:464:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:464:in `block in eager_load!'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:462:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:462:in `eager_load!'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:347:in `eager_load!'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
/app/config/environment.rb:5:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:249:in `block in run_tasks_blocks'
Tasks: TOP => db:migrate => environment
I have tried to include and not include Sprockets in the Uploader file and get the same error either way. I understand that Sprockets is no longer included in the master for Rails 4. I have now installed the sprockets-rails and sprockets-helper gems. I have also tried to require them at the top of the file (I don't understand this completely, but following this suggestion https://github.com/petebrowne/sprockets-helpers). Nothing has worked. Any suggestions about how I can go about resolving this. How do I initialize Sprockets::Helpers. Thanks.
I was making a pretty silly mistake. I had corrected files in my app and as committing the changes to the master, but I kept running the heroku run rake db:migrate command and getting the same error, so I didn't think I have resolved it yet. I had forgotten to push the new version to heroku! Hence the reason for still getting the same error.
Also, in case anyone else has a similar issue. Make sure you have fixed this:
https://github.com/carrierwaveuploader/carrierwave/issues/1020
I'm having problems using Mailer from the command prompt in my production environment. Using this command
Mailer.function.deliver
Gives this error
Errno::ENOTDIR: Not a directory - /assets/
from /home/rails/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/open-uri.rb:35:in `initialize'
from /home/rails/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/open-uri.rb:35:in `open'
from /home/rails/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/open-uri.rb:35:in `open'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/premailer-rails3-1.2.0/lib/premailer-rails3/css_helper.rb:70:in `request_and_unzip'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/premailer-rails3-1.2.0/lib/premailer-rails3/css_helper.rb:45:in `load_css_at_path'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/premailer-rails3-1.2.0/lib/premailer-rails3/css_helper.rb:15:in `css_for_doc'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/premailer-rails3-1.2.0/lib/premailer-rails3/premailer.rb:14:in `initialize'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/premailer-rails3-1.2.0/lib/premailer-rails3/hook.rb:18:in `new'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/premailer-rails3-1.2.0/lib/premailer-rails3/hook.rb:18:in `delivering_email'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.3.3/lib/mail/mail.rb:230:in `block in inform_interceptors'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.3.3/lib/mail/mail.rb:229:in `each'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.3.3/lib/mail/mail.rb:229:in `inform_interceptors'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.3.3/lib/mail/message.rb:218:in `inform_interceptors'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.3.3/lib/mail/message.rb:228:in `deliver'
from (irb):1
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /home/rails/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'1.9.3-p194 :002 >
I can correct the problem if I delete the 'public/assets' folder, however this causes the rest of the production website to fail at loading images/css, etc.
I precompile my assets using this command rake assets:precompile
Figured it out. Seems in production for rails 3.1 pre-compiled assets pipeline, premailer requires you have at least a blank email.css under app/assets/stylesheets before you pre-compile your assets.