# Highlighint rjs problem on a new product

**URL:** <https://www.ruby-forum.com/t/highlighint-rjs-problem-on-a-new-product/147606>\
**Category:** Rails\
**Created:** [September 3, 2008, 4:16pm UTC](https://www.ruby-forum.com/t/highlighint-rjs-problem-on-a-new-product/147606 "2008-09-03T16:16:49Z")\
**Posts on this page:** 3\
**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, 4:16pm UTC](https://www.ruby-forum.com/t/highlighint-rjs-problem-on-a-new-product/147606/1 "2008-09-03T16:16:49Z")

</div>

Hi,

Problem Summary:

I have been trying to add the highlight effect to my table but  
everytime a new record is added the highlighting gives an rjs error.  
However when i click the add to cart button on a product that already  
exists inside the table, the highlight effect works. Is this because  
the partial must only have only one

 in it and the   
must be on the other page that is rendering that partial?
## View Code:

\<% for product in @lineprice %\>

\<% if product.groceries.id == @item.groceries\_id %\>

 \<% else %\> \<% end %\> \<% end %\>

|
| |
| \<%= product.groceries.brand %\> | \<%= product.groceries.name %\> | \<%= product.quantity %\> | \<%= qx(product,"c") %\>\<% totalC += qx(product,"c")%\> | \<%= qx(product,"n") %\>\<% totalN += qx(product,"n") %\> | \<%= qx(product,"s") %\>\<% totalS += qx(product,"s") %\> | \<%= qx(product,"g") %\>\<% totalG += qx(product,"g") %\> | \<%= qx(product,"ca") %\>\<% totalCa += qx(product,"ca") %\> | item:\<%= @item.groceries\_id%\>Product:\<%= product.groceries.id %\> | \<%= cheapest=product.groceries.supermarket.attributes.except('id', 'groceries\_id','created\_at','updated\_at').values.min %\> \<%= Groceries.namecompare2(product) %\>\<% totalCh += cheapest %\> |

-------------------------------------------

Form Code:

* * *

```
<% form_remote_tag :url => {:controller => "sgpanel", :action =>

```

“add\_to\_cart”, :ad =\> params[:id] , :bd =\> groceries.id } do %\>

\<%= submit\_tag “Add to Cart” %\>  
\<% end %\>

* * *

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

Js.rjs code:

page.replace\_html ‘calculated’, :partial =\> ‘add\_to\_cart’  
page[:highlighted].visual\_effect :highlight,:startcolor =\>  
“#88ff88” ,:endcolor =\> “#FFFFFF”

---

<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 4, 2008, 10:18am UTC](https://www.ruby-forum.com/t/highlighint-rjs-problem-on-a-new-product/147606/2 "2008-09-04T10:18:04Z")

</div>

No need help anymore solved!

---

<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, 4:55pm UTC](https://www.ruby-forum.com/t/highlighint-rjs-problem-on-a-new-product/147606/3 "2008-09-03T16:55:29Z")

</div>

I think i am nearer to the problem. it looks like the controller  
add\_to\_cart function cannot save a new item and display it  
correspondingly into the ajax parital.

I tried doing this

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

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

respond_to do |format|
format.js
end

```

end

and the ajax partial would not update itself
