I have a model:
class Relatorio < ApplicationRecord
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
And I have this "before action" on super abstract Controller: "set_model_name":
@model_name ||= controller_name.classify
@model_class ||= controller_name.classify.constantize
In the line "constantize" of "controller_name.classify.constantize" from the set_model_name I got this error:
#<NoMethodError: undefined method `belongs_to' for Relatorio:Class>"
But after change the model to to use "ActiveRecord::Base" instead of "ApplicationRecord" the problem did not occur anymore :
class Relatorio < ActiveRecord::Base
The problem is the use of "ActiveRecord::Base" is not the default and not is recommended to prevent monkey patching of "ActiveRecord".
What is the way to do "constantize" in a string changing that to Model, in cases where the model inherited from ActiveRecord ?