Topic: Depot - Rails 3 Beta - Ajax problem

everything was going along fine until i got to the ajax part.  Now when you click on the Add to Cart it adds the product but does not keep the page.  It gives me a blank page and if I go back I can see it added the product.  It should maintain the current page and just update the cart. 

Does anyone happen to know what is going on.  I would like to get this handled because Rails 3 beta has been working.  I have the page from interwitingly that outlines the changes.

Thank you

Last edited by roamy (2010-03-14 22:13:48)

Re: Depot - Rails 3 Beta - Ajax problem

Is this just a dumb question or is there no answer??


Re: Depot - Rails 3 Beta - Ajax problem

You haven't given anyone any code to work from, roamy. We can't guess what could be wrong based on "it used to work, and now it doesn't keep the page." I don't even know what "keep the page" means.

Re: Depot - Rails 3 Beta - Ajax problem

These were the files modified for the ajax cart. please advise if you want the entire file.

edit app/views/store/index.html.erb
     <% form_tag({:action=>'add_to_cart', :id=>product}, :remote=>true) do %>
       <%= submit_tag "Add to Cart" %>
     <% end %>

edit app/views/layouts/store.html.erb
   <title>Pragprog Books Online Store</title>
   <%= stylesheet_link_tag "depot", :media => "all" %>
   <%= javascript_include_tag :defaults %>

edit app/controllers/store_controller.rb
   def add_to_cart
     product = Product.find(params[:id])
     @cart = find_cart
     respond_to do |format|
   rescue ActiveRecord::RecordNotFound
     logger.error("Attempt to access invalid product #{params[:id]}")
     redirect_to_index("Invalid product")

edit app/views/store/add_to_cart.js.rjs
page.replace_html("cart", :partial => "cart", :object => @cart)