Search code examples
ruby-on-railsjsonrubyrenderupgrade

Upgrading rails 4.2.8 to 5.0.x


I am in a process of upgrading my old rails app built with rails 4.2.8 to rails 5.0.x (tried versions of rails 5.0.1 and 5.0.7 and having the same issue).

The base rails app upgrade went fine and my base rails app is working fine. However, there is an frontend app built in angular and also one built with nodejs which have some communications channels like api and some controller to communicate with base rails app.

I am having issue in one of these controllers on line:

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

The error is:

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

So, I know I need to update/change attr_accessible and attr_protected feature in favor of Strong Parameters. And I see them in models but I am not sure does this have effect even for just response methods or so... I did update models to use ApplicationRecord instead ActiveRecord::Base.

Also, I did updated jbuilder to last version 2.11.x.

So, is there any suggestions for the solution? Obviously I am missing something?

enter image description here

enter image description here

enter image description here

Here is a preview of models and controller where errors shows.


Solution

  • After 2-3 days investigating issue I managed to fix it by adding missing methods to the required model as attr_accessor like this:

    attr_accessor  :blockAttributes, :entityFormTemplateBlock...
    

    Because I had issues in 15 models I had to optimize my fix by creating ruby module and include it into required models.

    Sample of module in rails app/lib/custom_attr_accessors.rb

    module CustomAttrAccessors
        attr_accessor  :blockAttributes, :entityFormTemplateBlock..
    end
    

    and finally include that module into model:

    class Formtemplate < ApplicationRecord
      include CustomAttrAccessors
    .....