Ruby-on-rails 未定义的方法 raise_in_transactional_callbacks=' 用于 ActiveRecord::Base:Class (NoMethodError)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28006358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:03:16  来源:igfitidea点击:

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

ruby-on-railsruby

提问by NorthLegion

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

执行 rails 生成脚手架时出错 用户名:string email:string

rake aborted! undefined method `migration_error=' for ActiveRecord::Base:Class

耙子中止!ActiveRecord::Base:Class 的未定义方法 `migration_error='

Error launching Rails server: undefined method 'configure'

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



When I try to start a new application (for Hartl's tutorial, Chapter 2), at the stage scaffoldstart, I got an error like:

当我尝试启动一个新应用程序时(对于 Hartl 的教程,第 2 章),在脚手架启动阶段,我收到如下错误:

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

But thanks to the above examples, I edited the development.rbfile:

但是由于上面的例子,我编辑了development.rb文件:

DemoApp::Application.configure do

(Yes, my application is called demo_appso I transformed its name).

(是的,我的应用程序叫做demo_app,所以我改变了它的名字)。

After that, I tried to run scaffoldagain but got a new error:

之后,我尝试再次运行scaffold但出现新错误:

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

In response to similar cases indicates a migrationmethod - that it should be removed from the file development.rb. Similarly, I tried to find in this file raise_in_transactional_callbacksmethod, but it's not there! In addition, I would say that the full code that produces in cmd is very large:

在响应类似的情况下表明一个迁移方法 - 它应该从文件 development.rb 中删除。同样,我试图在这个文件中找到raise_in_transactional_callbacks方法,但它不存在!另外,我会说在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>'

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

其中...(省略号) - 特意剪下类似的代码。就这样。我将不胜感激!

回答by Brad Werth

Your config/application.rbhas the following line:

config/application.rb有以下几行:

config.active_record.raise_in_transactional_callbacks = true

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.

这在您的 Rails 版本中不是有效的配置值。您需要将其删除或将其注释掉才能继续。



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.

注意:此错误和继续它的错误表明Rails 版本更改不完整。如果您正处于教程的早期阶段,您可能会认真考虑从一开始就使用您喜欢的 Rails 版本重新启动您的应用程序。这将帮助您避免此类错误,直到您更加熟悉该技术。

回答by Varus Septimus

I had the same issue when upgrading an app from Rails 5.0.1 to Rails 5.1.0.beta1.

将应用程序从 Rails 5.0.1 升级到 Rails 5.1.0.beta1 时,我遇到了同样的问题。

When starting the server (rails s), I got the following error message:

启动服务器 ( rails s) 时,我收到以下错误消息:

/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/application.rb,解决了这个问题......

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

经过一番调查,我发现这条线在 Rails 4.2.1 中是默认的,在 Rails 5.0.0 中消失了,现在在 Rails 5.1.0.beta1 中引发了一个错误......

回答by Ken Hill

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

如果你没有看到config.active_record.raise_in_transactional_callbacks = trueconfig/application.rb它可能会在您的环境CONFIGS存在。对于我的应用程序它被设置它config/environments/development.rbconfig/environments/test.rb