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?