Sinatra 事务回调警告中的 Activerecord

Wil*_* Hu 5 sinatra

带有 activerecord gem 的 Sinatra 项目发出警告:

DEPRECATION WARNING: Currently, Active Record suppresses errors raised
within `after_rollback`/`after_commit` callbacks and only print them
to the logs. In the next version, these errors will no longer be
suppressed. Instead, the errors will propagate normally just like in
other Active Record callbacks.

You can opt into the new behavior and remove this warning by setting:


**config.active_record.raise_in_transactional_callbacks = true**
Run Code Online (Sandbox Code Playgroud)

Gemfile.lock

activemodel (4.2.0)

      activesupport (= 4.2.0)
      builder (~> 3.1)
Run Code Online (Sandbox Code Playgroud)

如何删除这个?谢谢!

编辑:迷你项目在这里https://gist.github.com/williamhqs/c127e5d7018aa61cb02a

Pat*_*ity 5

错误消息告诉您该怎么做。在 Rails 中,暂时将此行添加到您的应用程序中:

config.active_record.raise_in_transactional_callbacks = true
Run Code Online (Sandbox Code Playgroud)

在 Sinatra 中,您可以直接在ActiveRecord::Base

ActiveRecord::Base.raise_in_transactional_callbacks = true
Run Code Online (Sandbox Code Playgroud)

请记住,此配置选项本身将在 Active Record 的下一个版本中被弃用。