# Clicking a form\_remote\_tag has no action

**URL:** <https://www.ruby-forum.com/t/clicking-a-form-remote-tag-has-no-action/108091>\
**Category:** Rails\
**Created:** [June 28, 2007, 11:58pm UTC](https://www.ruby-forum.com/t/clicking-a-form-remote-tag-has-no-action/108091 "2007-06-28T23:58:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeannibee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85e7bf/32.png) [@jeannibee](https://www.ruby-forum.com/u/jeannibee)\
**Post date:** [June 28, 2007, 11:58pm UTC](https://www.ruby-forum.com/t/clicking-a-form-remote-tag-has-no-action/108091/1 "2007-06-28T23:58:11Z")

</div>

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? 🙂

---

<div class="post-metadata">

**Author:** ![jeannibee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85e7bf/32.png) [@jeannibee](https://www.ruby-forum.com/u/jeannibee)\
**Post date:** [June 29, 2007, 12:19am UTC](https://www.ruby-forum.com/t/clicking-a-form-remote-tag-has-no-action/108091/2 "2007-06-29T00:19:59Z")

</div>

On 6/28/07, Jean N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![jeannibee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85e7bf/32.png) [@jeannibee](https://www.ruby-forum.com/u/jeannibee)\
**Post date:** [June 29, 2007, 2:03am UTC](https://www.ruby-forum.com/t/clicking-a-form-remote-tag-has-no-action/108091/3 "2007-06-29T02:03:39Z")

</div>

> 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!
