Rails upgrade from 5.0 to 5.1 - Cannot start webrick [duplicate] - ruby-on-rails

Before writing this question I looked at these answers, but was unable to find a solution.:
Error when execute rails generate scaffold User name:string email:string
rake aborted! undefined method `migration_error=' for ActiveRecord::Base:Class
Error launching Rails server: undefined method 'configure'
When I try to start a new application (for Hartl's tutorial, Chapter 2), at the stage scaffold start, I got an error like:
**undefined method `configure' for #<SampleApp2::Application:0x00000101a74610> (NoMethodError)**
But thanks to the above examples, I edited the development.rb file:
DemoApp::Application.configure do
(Yes, my application is called demo_app so I transformed its name).
After that, I tried to run scaffold again but got a new error:
**method_missing': undefined method raise_in_transactional_callbacks=' for ActiveRecord::Base:Class (NoMethodError)**
In response to similar cases indicates a migration method - that it should be removed from the file development.rb. Similarly, I tried to find in this file raise_in_transactional_callbacks method, but it's not there!
In addition, I would say that the full code that produces in cmd is very large:
C:\Sites\demo_app>rails generate scaffold User name:string email:string
invoke active_record
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `raise_in_transactional_callbacks=' for ActiveRecord::Base:Class (NoMethodError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.2/lib/active_record/railtie.rb:166:in `block (3 levels) in <class:Railtie>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.2/lib/active_record/railtie.rb:165:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.2/lib/active_record/railtie.rb:165:in `block (2 levels) in <class:Railtie>'
…
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/commands.rb:48:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Where the ...(ellipsis) - specially cut similar code.
That's all. I would be grateful for any help!

Your config/application.rb has the following line:
config.active_record.raise_in_transactional_callbacks = true
This is not a valid configuration value in your version of Rails. You will need to delete it or comment it out to continue.
Note: this error and the one that preceded it are indicative of an incomplete Rails version change. If you are in the early stages of a tutorial, you might seriously consider restarting your application using your preferred version of Rails from the very start. This will help you avoid this type of error until you are more familiar with the technology.

I had the same issue when upgrading an app from Rails 5.0.1 to Rails 5.1.0.beta1.
When starting the server (rails s), I got the following error message:
/home/user01/.rvm/gems/ruby-2.4.0#global/gems/activerecord-5.1.0.beta1/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `raise_in_transactional_callbacks=' for ActiveRecord::Base:Class (NoMethodError)
Same ills, same cures.
Commenting out the following line, in config/application.rb, solved the issue...
config.active_record.raise_in_transactional_callbacks = true
After some investigation, I found that this line was default in Rails 4.2.1, vanished in Rails 5.0.0, and now raises an error in Rails 5.1.0.beta1...

If you don't see config.active_record.raise_in_transactional_callbacks = true in config/application.rb it might exist in your environment configs. For my app it was being set it in config/environments/development.rb and config/environments/test.rb

Related

`method_missing': undefined method `has_paper_trail'

I am upgrading my rails app from 5.1.4 to 5.2.0. I am getting the following error. I would appreciate any help debugging this. I have not put the entire stack trace below, please let me know if you need it.
I have paper_trail version 12.1.0 installed. Its odd though, I had been using ruby version 2.5.1 with rails version 5.1.4 and it never gave me errors. This error started only after I upgraded to rails 5.2.0
redd#tanya:~/galaxy$ rails s
[DEPRECATED] Bootsnap's `autoload_paths_cache:` option is deprecated and will be removed. If you use Zeitwerk this option is useless, and if you are still using the classic autoloader upgrading is recommended.
[DEPRECATED] Bootsnap's `disable_trace:` option is deprecated and will be removed. If you use Ruby 2.5 or newer this option is useless, if not upgrading is recommended.
DEPRECATION WARNING: The factory_girl gem is deprecated. Please upgrade to factory_bot. See https://github.com/thoughtbot/factory_bot/blob/v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md for further instructions. (called from <main> at /home/redd/galaxy/config/application.rb:9)
=> Booting Puma
=> Rails 5.2.7 application starting in development
=> Run `rails server -h` for more startup options
/home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-5.2.7/lib/active_record/type.rb:27: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-5.2.7/lib/active_record/type/adapter_specific_registry.rb:9: warning: The called method `add_modifier' is defined here
/home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activemodel-5.2.7/lib/active_model/type/integer.rb:13: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activemodel-5.2.7/lib/active_model/type/value.rb:8: warning: The called method `initialize' is defined here
/home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-5.2.7/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb:12: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activemodel-5.2.7/lib/active_model/type/value.rb:8: warning: The called method `initialize' is defined here
Exiting
Traceback (most recent call last):
120: from bin/rails:3:in `<main>'
119: from bin/rails:3:in `load'
....
8: from /home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-5.2.7/lib/active_support/dependencies.rb:661:in `new_constants_in'
7: from /home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-5.2.7/lib/active_support/dependencies.rb:476:in `block in load_file'
6: from /home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
5: from /home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
4: from /home/redd/galaxy/app/models/users/user.rb:1:in `<main>'
3: from /home/redd/galaxy/app/models/users/user.rb:2:in `<class:User>'
2: from /home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/attr_encrypted-3.1.0/lib/attr_encrypted/adapters/active_record.rb:131:in `method_missing_with_attr_encrypted'
1: from /home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/attr_encrypted-3.1.0/lib/attr_encrypted.rb:306:in `method_missing'
/home/redd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-5.2.7/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `has_paper_trail' for #<Class:0x000055c56bb2be30> (NoMethodError)
Did you mean? has_attached_file
Get the full stack trace (not the shortened version you listed above)
Find the lines containing /home/redd/galaxy/config/initializers
Insert the following code at the top of these files:
# Loading `User` below would fail
# if `User.has_paper_trail` is not loaded already
require "paper_trail/frameworks/active_record"

Adding Devise to Rails app NoMethodError: undefined method `devise' for User (call 'User.connection' to establish a connection

When adding Devise to an application with an existing User making the mistake of forgetting to run the installer, it seems to bork the application, database can't migrate and devise routes aren't available when running rails routes; NoMethodError: undefined method `devise' for User (call 'User.connection' to establish a connection
Environment
Ruby 2.6.3
Rails 6.1.3
Devise 4.7.3
example app
https://github.com/jasonfb/DEVISE002
steps to reproduce
1- rails new TestApp
2- cd TestApp/
3- add gem devise to Gemfile & bundle install
4- Now, create a User model (as if you had a User model existing before you added Devise to your app) , do this with rails generate model User
5- now make the mistake of forgetting to run the devise installer itself
6- now run the devise generator on your already-created User with rails generate devise User
7- run rails db:migrate. this migration will FAIL, throwing the following error:
(does not make sense, because devise is installed into the gem file)
jason#MBP ~/Work/_LEARNING/Turbo-Rails/DEVISE002 (master) $ rails db:migrate
rails aborted!
NoMethodError: undefined method `devise' for User (call 'User.connection' to establish a connection):Class
/Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/app/models/user.rb:4:in `<class:User>'
/Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/app/models/user.rb:1:in `<main>'
/Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/config/routes.rb:2:in `block in <main>'
/Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/config/routes.rb:1:in `<main>'
/Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/config/environment.rb:5:in `<main>'
/Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/bin/rails:5:in `<top (required)>'
/Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/bin/spring:10:in `block in <top (required)>'
/Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/bin/spring:7:in `tap'
/Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/bin/spring:7:in `<top (required)>'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)
Symptom 1: The database doesn't migrate and rails db:migrate crashes with the above error.
Symptom 2: on one of my test apps where I made this mistake, the devise routes didn't seem to load although devise_for :users was in the routes.rb file.
mistake
this happens explicitly when you add devise to an app with an already existing User and you forget to run rails generate devise:install
TO FIX: run rails generate devise:install

Why isn't Rails::Railstie initializing after I installed CarrierWave gem?

Installed Carrier Wave gem successfully; added an image uploader which also works. However, when I went to rails db:migrate after changing a table, a name error popped up:
NameError: uninitialized constant Rails::Railtie. Did you mean? Rails.
Most of the other questions I've found online have to do with other uninitialized constants-- not Rails!
Here's the error called with --trace:
rails aborted!
NameError: uninitialized constant Rails::Railtie
Did you mean? Rails
/Users/graceyang/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/carrierwave-1.3.1/lib/carrierwave.rb:60:in `<module:CarrierWave>'
/Users/graceyang/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/carrierwave-1.3.1/lib/carrierwave.rb:59:in `<top (required)>'
/Users/graceyang/Documents/Projects/JS Power/website/jspower/config/application.rb:2:in `require'
/Users/graceyang/Documents/Projects/JS Power/website/jspower/config/application.rb:2:in `<top (required)>'
/Users/graceyang/Documents/Projects/JS Power/website/jspower/Rakefile:4:in `require_relative'
/Users/graceyang/Documents/Projects/JS Power/website/jspower/Rakefile:4:in `<top (required)>'
None of my rails commands work anymore! I had just completed a successful rails g migration AddFieldNameToTable call before I called rails db:migrate and the error started.
*EDIT/UPDATE *
It works now with rake instead of rails db:
but if anyone can answer why, that would be great!
*EDIT/UPDATE *
Actually, still a problem... can't install things that need the rails command....I found that the project was running under Ruby 2 for some reason even though my gemfile states gem 'rails', '~> 5.0.6'

Installing Devise Gem: forcing your application to not access the DB or load models when precompiling assets error

Hi guys I am running through a tutorial where we are installing the Devise Gem. On one of the steps we are told to include this code:
config.assets.initialize_on_precompile = false
in our config/application.rb file
After doing this when I try to get help on my generator command by passing --help I get this error message:
$ rails generate devise --help
DL is deprecated, please use Fiddle
c:/Users/Javi/Desktop/rails_projects/reddit_on_rails/config/application.rb:4:in
`<top (required)>': undefined local variable or method `config' for main:Object
(NameError)
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.3
/lib/rails/commands.rb:43:in `require'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.3
/lib/rails/commands.rb:43:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
If I remove the previous peice of code from the config/application.rb file then I can pass the --help command to generate devise with no problem. I am not able to decipher the error message. Any ideas as to what happened and if it will be an issue moving forwards?
You run the generator with:
rails generate devise:install
and then you run rails generate devise User to add Devise to your existing User class (assuming it's named that).
rails generate devise --help just lists the options for the devise generator.

active_support/whiny_nil.rb:52:in `method_missing' error occurs when I upgrade my rails 2.3.3 project to 2.3.17

Our rails project version is 2.3.3. Recently, however, we decided to upgrade rails version to 2.3.17 to patch the security holes.
But after upgrade my rails gem, I got the following error.
Is there anyone whoh had a same problem?
benjamins-iMac:webapp benjamin$ script/server
=> Booting WEBrick
=> Rails 2.3.17 application starting on http://0.0.0.0:3000
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/rails-2.3.17/lib/rails/gem_dependency.rb:21.
/Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/activerecord-2.3.17/lib/active_record/associations.rb:48: warning: already initialized constant HasManyThroughCantAssociateThroughHasManyReflection
/Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-2.3.17/lib/active_support/whiny_nil.rb:52:in `method_missing': undefined method `name' for nil:NilClass (NoMethodError)
from /Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/rails-2.3.17/lib/initializer.rb:445:in `initialize_database_middleware'
from /Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/rails-2.3.17/lib/initializer.rb:182:in `process'
from /Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/rails-2.3.17/lib/initializer.rb:113:in `send'
from /Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/rails-2.3.17/lib/initializer.rb:113:in `run'
from /Users/benjamin/clue/webapp/config/environment.rb:6
from /Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:182:in `require'
from /Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:182:in `require'
from /Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:547:in `new_constants_in'
from /Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:182:in `require'
from /Users/benjamin/.rvm/gems/ruby-1.8.7-p370/gems/rails-2.3.17/lib/commands/server.rb:84
from script/server:3:in `require'
from script/server:3
benjamins-iMac:webapp benjamin$
And the ruby-1.8.7-p370/gems/rails-2.3.17/lib/initializer.rb:445's code is
ActionController::Base.session_store.name == 'ActiveRecord::SessionStore'
I resolved the problem.
The answer was at here.
http://johnpwood.net/2009/09/04/disabling-sessions-in-rails-2-3-4/
The error is never enough information to go off of alone. however, so simple things, did you run: sudo rake gems:install already?
Also, the database columns must be present for your ActiveRecord models to pick up. If the initial state is "no-database" and subsequent rake tasks call on models, then it would choke on nils. I see environment.rb in the stack trace, so I assume it got that far...
So you should note that if you are upgrading from older version to the newer one then environment.rb file also needs to be changed apart from others. See carefully the changes that you need to done specially the initializer tasks as all the problem lies there according to the error log.

Resources