Clicking a form_remote_tag has no action

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:

<% hidden_div_if(@cart.items.empty?, :id => "cart" ) do %> <%= render(:partial => "cart" , :object => @cart) %> <% end %>

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.

Your Cart
<%= render(:partial => "cart_item" , :collection => cart.items) %>
<% 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? :slight_smile:

On 6/28/07, Jean N. [email protected] wrote:

refresh the whole page AFTER hitting “Empty Cart” the cart isn’t
<%= render(:partial => “cart” , :object => @cart) %>

session[:cart] = nil redirect_to_index end

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.

Bob S. 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!