对于 ActiveRecord: : Base: Class (NoMethodError) ,未定义的方法 rise_in_transactional_callback =’

在写这个问题之前,我看了看这些答案,但是找不到答案:

错误执行轨道生成脚手架用户名: 字符串电子邮件: 字符串

Rake 已中止! ActiveRecord: : Base: Class 的未定义方法‘ mobile _ error =’

启动 Rails 服务器时出错: 未定义方法“ configure”


当我尝试启动一个新的应用程序(针对 Hartl 的教程,第2章)时,在 断头台启动阶段,我得到了一个错误,比如:

**undefined method `configure' for #<SampleApp2::Application:0x00000101a74610> (NoMethodError)**

但是多亏了上面的例子,我编辑了 发展 RB文件:

DemoApp::Application.configure do

(是的,我的应用程序名为 Demo _ app,所以我转换了它的名称)。

在那之后,我再次尝试运行 断头台,但是得到了一个新的错误:

**method_missing': undefined method raise_in_transactional_callbacks=' for ActiveRecord::Base:Class (NoMethodError)**

对于类似的情况,表明了一个 迁徙方法——应该从 development.rb 文件中删除它。类似地,我尝试在这个文件中查找 提高 _ in _ transactional _ 回调方法,但它不在那里! 此外,我想说的是,在 cmd 中生成的完整代码非常大:

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

其中... (省略号)-特别削减类似的代码。 就这样,如果有人帮忙,我会很感激的!

34270 次浏览

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