# Programming the dom in rails

**URL:** <https://www.ruby-forum.com/t/programming-the-dom-in-rails/147570>\
**Category:** Rails\
**Created:** [September 3, 2008, 8:15am UTC](https://www.ruby-forum.com/t/programming-the-dom-in-rails/147570 "2008-09-03T08:15:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![darren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@darren](https://www.ruby-forum.com/u/darren)\
**Post date:** [September 3, 2008, 8:15am UTC](https://www.ruby-forum.com/t/programming-the-dom-in-rails/147570/1 "2008-09-03T08:15:48Z")

</div>

hi

i’m pretty new to rails, so excuse me.

Is there a way to programmatically build the DOM tree in Rails? This  
seems a pretty fundamental feature to have …

eg, generating the view for a calendar. There’s a clear pattern of  
table/css elements, half-in-step with a bunch of data that’s going to  
appear on the calendar.

It would be clean to have two separate loops for these in code, one  
for the html stuff, one for the content. – or is there another way to  
keep these concerns separate?

or perhaps there is a clever (not ridic) design solution?

thanks,  
Darren

---

<div class="post-metadata">

**Author:** ![darren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@darren](https://www.ruby-forum.com/u/darren)\
**Post date:** [September 3, 2008, 5:05pm UTC](https://www.ruby-forum.com/t/programming-the-dom-in-rails/147570/2 "2008-09-03T17:05:27Z")

</div>

darren wrote:

> It would be clean to have two separate loops for these in code, one  
> for the html stuff, one for the content. – or is there another way to  
> keep these concerns separate?
> 
> or perhaps there is a clever (not ridic) design solution?

The usual way is the [script.aculo.us](http://script.aculo.us) builder module:

> **[GitHub - madrobby/scriptaculous: script.aculo.us is an open-source JavaScript...](https://github.com/madrobby/scriptaculous)**
>
> script.aculo.us is an open-source JavaScript framework for visual effects and interface behaviours. - GitHub - madrobby/scriptaculous: script.aculo.us is an open-source JavaScript framework for vis...

though sometimes a good way is to render a display:none  
HTML template in the page, make clones of that, and loop  
through replacing dummy text nodes with real data.

–  
Rails Wheels - Find Plugins, List & Sell Plugins -  
[http://railswheels.com](http://railswheels.com)

---

<div class="post-metadata">

**Author:** ![darren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@darren](https://www.ruby-forum.com/u/darren)\
**Post date:** [September 3, 2008, 8:47pm UTC](https://www.ruby-forum.com/t/programming-the-dom-in-rails/147570/3 "2008-09-03T20:47:57Z")

</div>

Thanks for the feedback Mark.

I don’t think scriptaculous’ Builder is what I’m after as it’s  
JavaScript, but it seems the Rails/Rubyforge Builder is the server-  
side equivalent that I’m after.

Cheers,  
Darren

On Sep 3, 8:00 am, Mark Reginald J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![darren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@darren](https://www.ruby-forum.com/u/darren)\
**Post date:** [September 4, 2008, 4:46am UTC](https://www.ruby-forum.com/t/programming-the-dom-in-rails/147570/4 "2008-09-04T04:46:14Z")

</div>

perhaps they’re actually related … i didn’t actually think to check

🙂
