Undefined method raise_in_transactional_callbacks=' for ActiveRecord::Base:Class (NoMethodError)

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

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 #<: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 ' 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 ' … from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/commands.rb:48:in `' from bin/rails:4:in `require' from bin/rails:4:in `
'

Where the ...(ellipsis) - specially cut similar code. That's all. I would be grateful for any help!

回答1:

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 proceeded 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.



回答2:

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...



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!