# Saving to mysql while displaying a partial that calls for the list of mysql items lags

**URL:** <https://www.ruby-forum.com/t/saving-to-mysql-while-displaying-a-partial-that-calls-for-the-list-of-mysql-items-lags/147627>\
**Category:** Rails\
**Created:** [September 3, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/saving-to-mysql-while-displaying-a-partial-that-calls-for-the-list-of-mysql-items-lags/147627 "2008-09-03T19:00:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tyliong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e9a140/32.png) [@tyliong](https://www.ruby-forum.com/u/tyliong)\
**Post date:** [September 3, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/saving-to-mysql-while-displaying-a-partial-that-calls-for-the-list-of-mysql-items-lags/147627/1 "2008-09-03T19:00:33Z")

</div>

Hi,

Originally this was part of my highlighting question but now after  
debugging and slicing up the problem i found that the problem was not  
rjs but that saving to database does not sync with the ajax partial

Controller code:

* * *

def add\_to\_cart  
@sguser = Sguser.find(params[:ad])  
@lineprice = SglineItem.find(:all, :conditions =\> “sguser\_id =  
#{params[:ad]}”)

```
if SglineItem.find(:first, :conditions => ['sguser_id =? and

```

groceries\_id =?’, params[:ad], params[:bd]])== nil

```
@item = SglineItem.new
@item.sguser_id= params[:ad]
@item.groceries_id=params[:bd]
@item.save!

else

@item = SglineItem.find(:first, :conditions => ['sguser_id =? and

```

groceries\_id =?’, params[:ad], params[:bd]])  
@item.quantity +=1  
@item.save!

```
end

respond_to do |format|
format.js
end

```

end

* * *

although the @item is saved into the mysql database when respond\_to do  
|format| is evoked it does not see any of the changes. am I right to  
say that the save and the ajax call are being sent together in the  
same stream of data? hence the data that is saved into the mysql  
database while the partial displays the products of the database  
before the save is noticed? is there a way to break the data into 2  
seperate streams and delay the stream for the ajax ? What is the  
normal procedure for displaying ajax partials that update database  
information? do i have to use session data to store the products then  
save them to the database?
