# Div\_for and RJS

**URL:** <https://www.ruby-forum.com/t/div-for-and-rjs/167522>\
**Category:** Rails\
**Created:** [May 8, 2009, 11:05pm UTC](https://www.ruby-forum.com/t/div-for-and-rjs/167522 "2009-05-08T23:05:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![radkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@radkin](https://www.ruby-forum.com/u/radkin)\
**Post date:** [May 8, 2009, 11:05pm UTC](https://www.ruby-forum.com/t/div-for-and-rjs/167522/1 "2009-05-08T23:05:16Z")

</div>

Do you have to use an activeRecord object for div\_for?  
Perhaps I’m taking the wrong approach for “dynamic” divs

so far my education:

1. id= , is fine for just one div and prototype activity in an RJS (I  
got this to work)
2. class= , another option, but I don’t see how it can be used
3. div\_for , a helper that uses ActiveRecord objects to come up with  
multiple divs

Below: code that is my best guess for how to proceed, but it doesn’t do  
everything it is supposed to do:

---

<div class="post-metadata">

**Author:** ![radkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@radkin](https://www.ruby-forum.com/u/radkin)\
**Post date:** [May 8, 2009, 11:08pm UTC](https://www.ruby-forum.com/t/div-for-and-rjs/167522/2 "2009-05-08T23:08:37Z")

</div>

the code is here  
[http://pastie.org/472556](http://pastie.org/472556)  
and here  
[http://pastie.org/472563](http://pastie.org/472563)

sorry about the extra bits

---

<div class="post-metadata">

**Author:** ![radkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@radkin](https://www.ruby-forum.com/u/radkin)\
**Post date:** [May 9, 2009, 1:32am UTC](https://www.ruby-forum.com/t/div-for-and-rjs/167522/3 "2009-05-09T01:32:20Z")

</div>

The class will not work for a rjs call… html class elements are not  
unique by design so that is not a good idea anywho…

Here is a good description for div\_for  
[http://apidock.com/rails/ActionView/Helpers/RecordTagHelper/div\_for](http://apidock.com/rails/ActionView/Helpers/RecordTagHelper/div_for)

It’s just a way to create a div that has something todo with the  
record that you have. So if you have a @user object with id of 1 you  
would get id=“user\_1” for the div.
