Trying to achieve drag and drop "add to cart" as in p. 156-160 of RoR
E-Commerce and my action works and the product is added to the cart, but
my RJS file isn''t firing and making my magic happen. What have I
missed?
class CartController < ApplicationController
def add
@book = Book.find(params[:id])
if request.xhr?
@item = @cart.add(params[:id])
flash.now[:cart_notice] = "#{@book.title} added to your cart."
render :action => "add_with_ajax"
#snip!
end
add_with_ajax.rjs
page.replace_html "shopping_cart", :partial => "cart"
page.visual_effect :highlight, "cart_item_#{@item.book.id}",
:duration => 3
page.visual_effect :fade, "cart_notice", :duration => 3
Things that DO work:
1) the products are draggable (drags onto shopping_cart with method
"add")
2) the drop zone "shopping_cart" works
3) products are added to the cart, total is updated, all logic works
So if the drop zone works why isn''t page.replace_html replacing? I
have
to do manual refreshes. Same with the visual_effects. This leads me to
believe that the RJS isn''t firing at all. Anyone have an idea why?
--
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
-~----------~----~----~----~------~----~------~--~---
Try render :partial => ''add_with_ajax'' Jason On 12/7/06, Taylor Strait <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Trying to achieve drag and drop "add to cart" as in p. 156-160 of RoR > E-Commerce and my action works and the product is added to the cart, but > my RJS file isn''t firing and making my magic happen. What have I > missed? > > class CartController < ApplicationController > > def add > @book = Book.find(params[:id]) > > if request.xhr? > @item = @cart.add(params[:id]) > flash.now[:cart_notice] = "#{@book.title} added to your cart." > render :action => "add_with_ajax" > #snip! > end > > > add_with_ajax.rjs > page.replace_html "shopping_cart", :partial => "cart" > page.visual_effect :highlight, "cart_item_#{@item.book.id}", > :duration => 3 > page.visual_effect :fade, "cart_notice", :duration => 3 > > > Things that DO work: > 1) the products are draggable (drags onto shopping_cart with method > "add") > 2) the drop zone "shopping_cart" works > 3) products are added to the cart, total is updated, all logic works > > So if the drop zone works why isn''t page.replace_html replacing? I have > to do manual refreshes. Same with the visual_effects. This leads me to > believe that the RJS isn''t firing at all. Anyone have an idea why? > > -- > 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 -~----------~----~----~----~------~----~------~--~---
I guess I should have read the logs:
ActionView::TemplateError (undefined method `book'' for true:TrueClass)
on line #2 of app/views/cart/add_with_ajax.rjs:
1: page.replace_html "shopping_cart", :partial => "cart"
2: page.visual_effect :highlight, "cart_item_#{@item.book.id}",
:duration => 3
3: page.visual_effect :fade, "cart_notice", :duration => 3
Replacing the variable in line 2 with, "cart_item_#{@book.id}" fixed
it.
Thanks.
--
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
-~----------~----~----~----~------~----~------~--~---
Is this an error in the book? I am compiling a list of errata to post on my blog. Thanks. On 12/7/06, Taylor Strait <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > > Replacing the variable in line 2 with, "cart_item_#{@book.id}" fixed it. > Thanks. > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Taylor Strait wrote:> I guess I should have read the logs: > > ActionView::TemplateError (undefined method `book'' for true:TrueClass) > on line #2 of app/views/cart/add_with_ajax.rjs: > 1: page.replace_html "shopping_cart", :partial => "cart" > 2: page.visual_effect :highlight, "cart_item_#{@item.book.id}", > :duration => 3 > 3: page.visual_effect :fade, "cart_notice", :duration => 3 > > Replacing the variable in line 2 with, "cart_item_#{@book.id}" fixed it. > Thanks.Hi Taylor, For some reason your @item object is true, instead of the actual item. If you take a look at pages 154 and 155, you can see that @item @cart.add(params[:id]) and that the add method should always return a cart item (on page 154), never a boolean value. So your fix works, but if your code is exactly as it is in the book, you should never get the error. Cheers, //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bala Paranj wrote:> Is this an error in the book? I am compiling a list of errata to post on my > blog. Thanks.Hi Bala, I would appreciate if you could post all the errors you find directly to me, we''re currently building an errata system to the companion site @ http://www.railsecommerce.com Thanks, //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---