# Code autogenerating

**URL:** <https://www.ruby-forum.com/t/code-autogenerating/93125>\
**Category:** Rails\
**Created:** [April 27, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/code-autogenerating/93125 "2007-04-27T23:09:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![madiba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58956e/32.png) [@madiba](https://www.ruby-forum.com/u/madiba)\
**Post date:** [April 27, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/code-autogenerating/93125/1 "2007-04-27T23:09:23Z")

</div>

I’ve seen in my code lots of repeating code connected with  
view(new/edit/  
delete. I’d like to write an autogenerator of code (I’m going to base on  
acts and scaffolding code).

Where in rails directory hierarchy should I put it?

–  
I’ve probably left my head… somewhere. Please wait untill I find it.  
Homepage (pl\_PL): [http://uzytkownik.jogger.pl/](http://uzytkownik.jogger.pl/)  
(GNU/)Linux User: #425935 (see [http://counter.li.org/](http://counter.li.org/))

---

<div class="post-metadata">

**Author:** ![madiba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58956e/32.png) [@madiba](https://www.ruby-forum.com/u/madiba)\
**Post date:** [April 28, 2007, 4:33am UTC](https://www.ruby-forum.com/t/code-autogenerating/93125/2 "2007-04-28T04:33:40Z")

</div>

Maciej P. wrote:

> I’ve seen in my code lots of repeating code connected with view(new/edit/  
> delete. I’d like to write an autogenerator of code (I’m going to base on  
> acts and scaffolding code).
> 
> Where in rails directory hierarchy should I put it?

The first line of defense is “Refactoring” (with unit tests) to “DRY”  
that  
code up, where DRY means “Don’t Repeat Yourself”.

Ruby is so good at folding abstractions together, you ought to work to  
get  
that repeating code down to a few single lines. If you then actually  
need to  
generate the code, the common classes that you extracted should fit  
perfectly inside it.

My Short Cut at O’Reilly has dozens of very effective techniques,  
including  
a few new assertions, to write unit tests for all kinds of View code,  
not  
just Ajax. The tests will make refactoring safe.

–  
Phlip  
[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax
