I moved my code into a module and now I get an error...
undefined method `delegate_fields_to' for Registration::Car::StepOne
However, the code worked fine before I put it in the module. What am I missing?
module Registration
class Base
module ActAsDelegation
def self.form_fields_mapping
[{}]
end
def self.fields_of_model(model)
form_fields_mapping.select {|record| record[:model] == model }.map {|record| record[:name] }
end
def self.delegate_fields_to(*models)
models.each do |model|
fields_of_model(model).each do |attr|
delegate attr.to_sym, "#{attr}=".to_sym, to: model if attr.present?
end
end
end
end
end
end
module Registration
class Base
include ActiveModel::Model
attr_reader :user
include ActAsDelegation
end
end
module Registration
module Car
class StepOne < Registration::Base
delegate_fields_to(:car, :truck)
end
end
end