Edipofederle Edipofederle
2008-Nov-29 21:02 UTC
Ajax magic does not work - Book Agil Development with Rails
Ajax magic does not work - Book Agil Development with Rails( Edition 2)
I''m trying to run the part where the effect is implemented in
application hightlight depot but is not working, I tried to download the
codes on the site but it also does not work so someone step
Sorry english evil, I am learning:)
Codes
cart.rb
<code>
def add_product(product)
current_item = @items.find {|item| item.product == product}
if current_item
current_item.increment_quantity
else
current_item = CartItem.new(product)
@items << current_item
end
current_item
end
</code>
store_controller
<code>
def add_to_cart
begin
product = Product.find(params[:id])
rescue ActiveRecord::RecordNotFound
logger.error("Attempt to access invalid product #{params[:id]}")
redirect_to_index("Invalid product")
else
@cart = find_cart
@current_item = @cart.add_product(product)
end
end
</code>
Partial _cart_item.rhtml
<code>
<% if cart_item == @current_item %>
<tr id="current_item">
<% else %>
<tr>
<% end %>
<td><%= cart_item.quantity %>×</td>
<td><%= h(cart_item.title) %> </td>
<td class="item-price"><%=
number_to_currency(cart_item.price)
%></td>
</tr>
</code>
add_to_cart.rjs
<code>
page.replace_html("cart", :partial => "cart", :object
=> @cart)
page[:current_item].visual_effect :highlight,
:startcolor =>
"#88ff88",
:endcolor =>
"#114411"
</code>
Thaks
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-30 00:36 UTC
Re: Ajax magic does not work - Book Agil Development with Rails
On Nov 29, 9:02 pm, Edipofederle Edipofederle <rails-mailing- l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ajax magic does not work - Book Agil Development with Rails( Edition 2) > > I''m trying to run the part where the effect is implemented in > application hightlight depot but is not working, I tried to download the > codes on the site but it also does not work so someone step >In what way does it not work? Fred> Sorry english evil, I am learning:) > > Codes > > cart.rb > <code> > def add_product(product) > current_item = @items.find {|item| item.product == product} > if current_item > current_item.increment_quantity > else > current_item = CartItem.new(product) > @items << current_item > end > current_item > end > </code> > > store_controller > <code> > def add_to_cart > begin > product = Product.find(params[:id]) > rescue ActiveRecord::RecordNotFound > logger.error("Attempt to access invalid product #{params[:id]}") > redirect_to_index("Invalid product") > else > @cart = find_cart > @current_item = @cart.add_product(product) > end > end > </code> > > Partial _cart_item.rhtml > <code> > <% if cart_item == @current_item %> > <tr id="current_item"> > <% else %> > <tr> > <% end %> > > <td><%= cart_item.quantity %>×</td> > <td><%= h(cart_item.title) %> </td> > <td class="item-price"><%= number_to_currency(cart_item.price) > %></td> > </tr> > </code> > > add_to_cart.rjs > > <code> > page.replace_html("cart", :partial => "cart", :object => @cart) > > page[:current_item].visual_effect :highlight, > :startcolor => > "#88ff88", > :endcolor => > "#114411" > > </code> > > Thaks > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---