# Active Scaffold controllers created dynamically at runtime?

**URL:** <https://www.ruby-forum.com/t/active-scaffold-controllers-created-dynamically-at-runtime/107883>\
**Category:** Rails\
**Created:** [June 27, 2007, 3:55am UTC](https://www.ruby-forum.com/t/active-scaffold-controllers-created-dynamically-at-runtime/107883 "2007-06-27T03:55:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlopke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mlopke](https://www.ruby-forum.com/u/mlopke)\
**Post date:** [June 27, 2007, 3:55am UTC](https://www.ruby-forum.com/t/active-scaffold-controllers-created-dynamically-at-runtime/107883/1 "2007-06-27T03:55:15Z")

</div>

Does anyone know how to link Rails’ routes into anonymous controller  
classes created at runtime (defined with their superclass as  
ActionController::Base)?

I’m trying to create a plugin for all of my projects that dynamically  
creates an active\_scaffold controller for each model. It would  
essentially be like a scaffold\_all\_models for active\_scaffold. I believe  
the original scaffold extensions mix in functionality to  
ActionController::Base, whereas active\_scaffold (greedily) requires a  
separate controller for each model it scaffolds… hence my attempt to  
create dynamic controllers.

PS: If anyone has already created a plugin like this, I would _gladly_  
just use yours 🙂

Thanks,  
Mike L.

---

<div class="post-metadata">

**Author:** ![mlopke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mlopke](https://www.ruby-forum.com/u/mlopke)\
**Post date:** [June 27, 2007, 5:08am UTC](https://www.ruby-forum.com/t/active-scaffold-controllers-created-dynamically-at-runtime/107883/2 "2007-06-27T05:08:09Z")

</div>

I like the idea. Many of the controllers have no real value and are  
degenerate. The generated controllers  
could even implement the recommended security provisions to only  
expose the nested action.

I was playing with routing for a different reason today, but it  
should not be that hard. The RouteSet looks at the path and extracts  
a set of parameter values from the environment, then asks each route  
in the set to match against the route. If it matches it extracts the  
parameter values from the path. Patching the extraction method to  
also generate a controller should be pretty straightforward.

patch write\_recognition to alias recognize and replace it with a  
wrapper method that also generates the controller. If that turns out  
to be a bit too late, do the same with recognition\_extraction.

Michael
