Task D: A Dash Of Ajax #2


-Yes :-)-


No. I found that StoreController.redirect_to_index method would complain. Here's what we had before:

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

Rails would complain "wrong number of arguments (0 for 1)". You can resolve this by setting the default value of the msg variable to nil as follows:

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

(Sidebar: if you're developing web applications for the first time, a handy Firefox extension you should use is the Web Developer Toolbar (https://addons.mozilla.org/firefox/60/). This handy toolbar allows you to easily test your Ajax-less experience at the click of a button.)


You should already have altered the method on the creation of the AJAX cart. Also, don't forget to use the statement modifier unless request.xhr? to handle the downgrade.


I've done like below:

def empty_cart
   session[:cart] = nil
   respond_to do |format|
     format.js if request.xhr?
     format.html {redirect_to_index}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License