# RJS concurrency problems with lists

**URL:** <https://www.ruby-forum.com/t/rjs-concurrency-problems-with-lists/109056>\
**Category:** Rails\
**Created:** [July 11, 2007, 2:55am UTC](https://www.ruby-forum.com/t/rjs-concurrency-problems-with-lists/109056 "2007-07-11T02:55:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [July 11, 2007, 2:55am UTC](https://www.ruby-forum.com/t/rjs-concurrency-problems-with-lists/109056/1 "2007-07-11T02:55:32Z")

</div>

Folks,

I’m using RJS to add and remove rows from a list of items. Ideally,  
when the list is empty, there should be a single row “You have no  
items”, otherwise the list looks confusing with the header but no  
items. Does anyone have a recipe for doing this?

Options include:

1. Update add and remove RJS templates to query the DB to get the item  
count, and remove/add the special row as necessary. Has concurrency  
issues.

2. When the page is initialized, put the display item count into the  
session, and update add/remove actions to keep it up-to-date. Update  
RJS templates as per option 1.

3. Implement a javascript function that takes the id of a list and  
iterates over its children, inserting the “You have no items” row if  
none.

I’m leaning towards option 2, but if there is a cleaner approach that  
would be awesome.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [July 11, 2007, 4:54am UTC](https://www.ruby-forum.com/t/rjs-concurrency-problems-with-lists/109056/2 "2007-07-11T04:54:44Z")

</div>

Chris,

The “you have no items” row could always be there. Just style it with  
relative positioning such that it sits _under_ (z-index) the first  
_real_ row of your list.

Cheers,  
Ken

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [July 11, 2007, 9:01am UTC](https://www.ruby-forum.com/t/rjs-concurrency-problems-with-lists/109056/3 "2007-07-11T09:01:59Z")

</div>

Works perfectly. Thanks!

Cheers,  
Chris
