正在将 rails 4.2.8 升级到 5.0.x

Upgrading rails 4.2.8 to 5.0.x

我正在将使用 rails 4.2.8 构建的旧 rails 应用程序升级到 rails 5.0.x(试用版本 rails 5.0.1 和 5.0.7 以及有同样的问题)。

基础 rails 应用程序升级顺利,我的基础 rails 应用程序运行良好。然而,有一个内置于 angular 的前端应用程序和一个使用 nodejs 构建的前端应用程序,它有一些通信渠道,如 api 和一些控制器与基础 rails 应用程序通信。

我在其中一个在线控制器中遇到问题:

  render(:json =>  result, methods: [:mdobjectsAttributes, :blockAttributes, :entityFormTemplateBlock], :status => 200, :errorCode => 0, :layout => false)

错误是:

NoMethodError (undefined method `mdobjectsAttributes' for #Formtemplateblock:0x000055d7ff2a6480>):

所以,我知道我需要 update/change attr_accessible 和 attr_protected 功能以支持强参数。我在模型中看到了它们,但我不确定这是否对 response methods 左右有影响...我确实更新了模型以使用 ApplicationRecord 而不是 ActiveRecord::Base.

此外,我确实将 jbuilder 更新到最新版本 2.11.x

那么,有什么解决方案的建议吗?显然我错过了什么?

这是显示错误的模型和控制器的预览。

在调查问题 2-3 天后,我设法通过向所需模型添加缺少的方法来修复它,如下所示 attr_accessor:

attr_accessor  :blockAttributes, :entityFormTemplateBlock...

因为我在 15 个模型中遇到问题,所以我必须通过创建 ruby 模块并将其包含到所需模型中来优化我的修复。

rails app/lib/custom_attr_accessors.rb

中的模块示例
module CustomAttrAccessors
    attr_accessor  :blockAttributes, :entityFormTemplateBlock..
end

最后将该模块包含到模型中:

class Formtemplate < ApplicationRecord
  include CustomAttrAccessors
.....