Hi
(Based on the CART exercise in the AWDWR book by the Pragmatic guys.)
I apologize in advance for being long winded, I just wanted to be
thorough since this is kinda still new to me.
In a nutshell, when I click my Empty Cart button which should launch an
AJAX call to the back end ''blind_up'' my cart, it
doesn''t. But if I
refresh the whole page AFTER hitting "Empty Cart" the cart
isn''t
displayed. So I surmise that the empty_cart action in my controller IS
being executed but my .rjs template isn''t being handled properly.
Here''s the gory details....
I have a ''layout'' page in (app/views/layout/store.rhtml)
calling a
partial like this:
<div id="side">
<% hidden_div_if(@cart.items.empty?, :id => "cart" ) do %>
<%= render(:partial => "cart" , :object => @cart) %>
<% end %>
</div>
the _cart.rhtml in (app/view/store) partial looks like this (Calling
another cart_item partial) contains a form_remote_tag to empty my cart.
<div class="cart-title">Your Cart</div>
<table>
<%= render(:partial => "cart_item" , :collection =>
cart.items) %>
</table>
</div>
<% form_remote_tag :url => { :action => :empty_cart } do %>
<%= submit_tag "Empty cart" %>
<% end %>
The app/controllers/store_controller.rb has the empty_cart method as
follows...
def empty_cart
session[:cart] = nil
redirect_to_index
end
private
def redirect_to_index( msg = nil )
flash[:notice] = msg if msg
redirect_to :action => :index
end
AND to ''dust it all off'' I have an
app/views/store/empty_cart.rjs file
that should be ''executed'' when the empty_cart action is hit.
page[:cart].visual_effect :blind_up
What the heck did I do wrong? :)
--
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
-~----------~----~----~----~------~----~------~--~---
On 6/28/07, Jean Nibee <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi > > (Based on the CART exercise in the AWDWR book by the Pragmatic guys.) > > I apologize in advance for being long winded, I just wanted to be > thorough since this is kinda still new to me. > > In a nutshell, when I click my Empty Cart button which should launch an > AJAX call to the back end ''blind_up'' my cart, it doesn''t. But if I > refresh the whole page AFTER hitting "Empty Cart" the cart isn''t > displayed. So I surmise that the empty_cart action in my controller IS > being executed but my .rjs template isn''t being handled properly. > > Here''s the gory details.... > > I have a ''layout'' page in (app/views/layout/store.rhtml) calling a > partial like this: > > <div id="side"> > <% hidden_div_if(@cart.items.empty?, :id => "cart" ) do %> > <%= render(:partial => "cart" , :object => @cart) %> > <% end %> > </div> > > the _cart.rhtml in (app/view/store) partial looks like this (Calling > another cart_item partial) contains a form_remote_tag to empty my cart. > > <div class="cart-title">Your Cart</div> > <table> > <%= render(:partial => "cart_item" , :collection => cart.items) %> > </table> > </div> > <% form_remote_tag :url => { :action => :empty_cart } do %> > <%= submit_tag "Empty cart" %> > <% end %> > > The app/controllers/store_controller.rb has the empty_cart method as > follows... > > > > def empty_cart > session[:cart] = nil > redirect_to_index > endYou shouldn''t redirect from empty_cart. You hinted have an empty_cart.rjs template, so that should display the cart or whatever. Use Firebug and trace your XHR''s so you can see what''s being returned. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Bob Showalter wrote: > > You shouldn''t redirect from empty_cart. You hinted have an > empty_cart.rjs template, so that should display the cart or whatever. > > Use Firebug and trace your XHR''s so you can see what''s being returned.Awesome, can''t believe it was such a small thing. (Forgot I had Firebug too.. just installed it the other night) Thanks much! -- 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 -~----------~----~----~----~------~----~------~--~---