1 Replies - 1080 Views - Last Post: 18 March 2010 - 02:03 PM Rate Topic: -----

#1 Tyler E  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 28-January 09

Problems with redirect_to

Posted 18 March 2010 - 01:31 PM

I'm having problems with an empty cart button. What I want it to do when I click the button is to empty the cart, do a blind_up effect, and redirect me to the index page. It does all of this except redirect me to the index.

Here's the methods in the controller:
def empty_cart
  session[:cart] = nil
  @cart = find_cart
  redirect_to_index unless request.xhr?

def redirect_to_index(msg = nil)
   flash[:notice] = msg
   redirect_to :action => 'index'

Here's the button:
<% form_remote_tag :url => { :action => :empty_cart } do %>
  <%= submit_tag "Empty cart" %>
<% end %>

And the blind_up javascript:
page[:cart].visual_effect :blind_up

Could you please tell me why the redirect_to_index method doesn't work.

Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: Problems with redirect_to

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Problems with redirect_to

Posted 18 March 2010 - 02:03 PM

Your redirect_to_index method isn't working because at the end of your empty_cart method, you tell your code to redirect to index unless the request is coming via an XMLHttpRequest (which it is, because you used form_remote_tag, instead of form_tag). Try switching to just form_tag (or reading a little further in the book), and you should be able to make things work the way you want them to.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1