How do I use an instance of another Controller as service object?

Hello !

How do I use an instance of another controller as service Object?

Personally, my problem-case is that I have a ActsAsPolymorphicTree Concern with a polymorphic join table, such that db_records of different types can be parent and children of each other.

The join table model “TreeLeafs” has a controller TreeLeafsController and the route takes the type and id of a parent and a child db_record.

So I have a multiplexer that is supposed to do what I ask for in the title.

I want the multiplexer to get the controller/record_type and action from the route and create an instance of the suchlike controller in order to render or invoke actions like “new” when I need a new instance variable of that kind.

it looks something like this then

controller_name = “#{resource_type.camelize.pluralize}”+“Controller”
controller_klass = Object.const_get(controller_name)
controller = controller_klass.new
request.filtered_parameters[:controller] = controller_name
controller.params = params
controller.request = request
controller.response = response
controller.send sym_controller_action

What would be the correct way to retrieve a newly created instance from this controller-service-object for instance? Can I somehow extract it from the request ?

Also it doesn’t work to call render on the controller instance. The view doesn’t have the instance variables created in the action at its disposal.

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs