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 <tr></tr> in it and the
<table>
must be on the other page that is rendering that partial?
View Code:
---------------------------------------
<table>
<% for product in @lineprice %>
<% if product.groceries.id == @item.groceries_id %>
<tr id="highlighted">
<% else %>
<tr>
<% end %>
<td><%= product.groceries.brand %></td>
<td><%= product.groceries.name %></td>
<td><%= product.quantity %></td>
<td><%= qx(product,"c") %><% totalC +=
qx(product,"c")%></td>
<td><%= qx(product,"n") %><% totalN +=
qx(product,"n") %></td>
<td><%= qx(product,"s") %><% totalS +=
qx(product,"s") %></td>
<td><%= qx(product,"g") %><% totalG +=
qx(product,"g") %></td>
<td><%= qx(product,"ca") %><% totalCa +=
qx(product,"ca") %></td>
<td>item:<%= @item.groceries_id%>Product:<%=
product.groceries.id
%></td>
<td><%cheapest=product.groceries.supermarket.attributes.except(''id'',
''groceries_id'',''created_at'',''updated_at'').values.min
%> <%Groceries.namecompare2(product) %><% totalCh += cheapest
%></td>
</tr>
<% end %>
<table>
-------------------------------------------
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"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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
On Sep 3, 10:16 pm, tyliong
<tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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 <tr></tr> in it and the
<table>
> must be on the other page that is rendering that partial?
>
> View Code:
> ---------------------------------------
> <table>
> <% for product in @lineprice %>
>
> <% if product.groceries.id == @item.groceries_id %>
> <tr id="highlighted">
> <% else %>
> <tr>
> <% end %>
> <td><%= product.groceries.brand %></td>
> <td><%= product.groceries.name %></td>
> <td><%= product.quantity %></td>
> <td><%= qx(product,"c") %><% totalC +=
qx(product,"c")%></td>
> <td><%= qx(product,"n") %><% totalN +=
qx(product,"n") %></td>
> <td><%= qx(product,"s") %><% totalS +=
qx(product,"s") %></td>
> <td><%= qx(product,"g") %><% totalG +=
qx(product,"g") %></td>
> <td><%= qx(product,"ca") %><% totalCa +=
qx(product,"ca") %></td>
> <td>item:<%= @item.groceries_id%>Product:<%=
product.groceries.id
> %></td>
> <td><%>
cheapest=product.groceries.supermarket.attributes.except(''id'',
>
''groceries_id'',''created_at'',''updated_at'').values.min
%> <%> Groceries.namecompare2(product) %><% totalCh += cheapest
%></td>
> </tr>
> <% end %>
> <table>
> -------------------------------------------
>
> 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"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
No need help anymore solved!
-----Original Message-----
From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
[mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of
tyliong
Sent: Wednesday, September 03, 2008 10:55 PM
To: Ruby on Rails: Talk
Subject: [Rails] Re: Highlighint rjs problem on a new product
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
On Sep 3, 10:16 pm, tyliong
<tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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 <tr></tr> in it and the
<table>
> must be on the other page that is rendering that partial?
>
> View Code:
> ---------------------------------------
> <table>
> <% for product in @lineprice %>
>
> <% if product.groceries.id == @item.groceries_id %>
> <tr id="highlighted">
> <% else %>
> <tr>
> <% end %>
> <td><%= product.groceries.brand %></td>
> <td><%= product.groceries.name %></td>
> <td><%= product.quantity %></td>
> <td><%= qx(product,"c") %><% totalC +=
qx(product,"c")%></td>
> <td><%= qx(product,"n") %><% totalN +=
qx(product,"n") %></td>
> <td><%= qx(product,"s") %><% totalS +=
qx(product,"s") %></td>
> <td><%= qx(product,"g") %><% totalG +=
qx(product,"g") %></td>
> <td><%= qx(product,"ca") %><% totalCa +=
qx(product,"ca") %></td>
> <td>item:<%= @item.groceries_id%>Product:<%=
product.groceries.id
> %></td>
> <td><%>
cheapest=product.groceries.supermarket.attributes.except(''id'',
>
''groceries_id'',''created_at'',''updated_at'').values.min
%> <%> Groceries.namecompare2(product) %><% totalCh += cheapest
%></td>
> </tr>
> <% end %>
> <table>
> -------------------------------------------
>
> 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"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---